Questions tagged [python]

Python is a dynamically typed, high-level interpreted programming language. Its design focuses on clear syntax, an intuitive approach to object-oriented programming, and making the right way to do things obvious. Python supports modules and exceptions, and has an extensive standard module library. Python is general-purpose and thus used widely, from the web to embedded systems.

Filter by
Sorted by
Tagged with
20
votes
3answers
7k views

How to decouple UI from logic on Pyqt/Qt apps properly?

I've read quite a lot about this subject in the past and watched some interesting talks like this one from Uncle Bob's. Still, I always find pretty difficult to architect properly my desktop ...
19
votes
3answers
16k views

Differences between “Java OOP” and “Pythonic OOP”? [closed]

I started with ActionScript 2.0 and then went on with Java. I have learned, or at least used, a bunch of languages since then, including Python (probably my favorite). I'm afraid that my style of ...
19
votes
4answers
7k views

Why coroutines are back? [closed]

Most of the groundwork for coroutines occurred in the 60s/70s and then stopped in favor of alternatives(e.g., threads) Is there any substance to the renewed interest in coroutines that has been ...
19
votes
4answers
10k views

Is colon in python blocks technically necesary?

This is really just a theoretical question by a python newbie who wants to understand more. I keep forgetting the colon after the block initial statements in python. Those are what I mean: for <...
19
votes
5answers
19k views

How difficult is Python and Django to pick up for a Java/.NET web developer? [closed]

I just started a new job a couple months ago at a small company where I am currently leading all development efforts present and future. I personally have years of experience in software design and ...
19
votes
1answer
40k views

Why use classes when programming a tkinter gui in python

I program primarily in python and have programmed a couple of GUI's with Tkinter, every tutorial I have ever seen has recommended defining and using a class for the GUI, but my GUI runs flawlessly ...
19
votes
7answers
11k views

Python mutable default argument: Why?

I know that default arguments are created at the function initialisation time and not every time the function is called. See the following code: def ook (item, lst=[]): lst.append(item) ...
19
votes
3answers
7k views

@staticmethod vs module-level function

This is not about @staticmethod and @classmethod! I know how staticmethod works. What I want to know is the proper use cases for @staticmethod vs. a module-level function. I've googled this ...
19
votes
3answers
6k views

Using a GPLv3 Python module, will my entire project have to be GPLv3 licensed?

I'm working on a small project right now that I plan on releasing under an open-source license (haven't decided which yet). The question I have is that one of the Python modules I use is licensed ...
18
votes
10answers
9k views

Why are inheritance and polymorphism so widely used?

The more I learn about different programming paradigms, such as functional programming, the more I begin to question the wisdom of OOP concepts like inheritance and polymorphism. I first learned ...
18
votes
8answers
5k views

What are good unit tests to cover the use case of rolling a die?

I'm trying to get to grips with unit testing. Say we have a die which can has a default number of sides equal to 6 (but can be 4, 5 sided etc.): import random class Die(): def __init__(self, ...
18
votes
8answers
2k views

Python Coding standards vs. productivity

I work for a large humanitarian organisation, on a project building software that could help save lives in emergencies by speeding up the distribution of food. Many NGOs desperately need our software ...
18
votes
4answers
3k views

Python decorators and Lisp macros

When looking Python decorators someone made the statement, that they are as powerful as Lisp macros (particularly Clojure). Looking at the examples given in PEP 318 it looks to me as if they are just ...
18
votes
3answers
15k views

Is it ok to have multiple classes in the same file in Python?

I'm freshly coming to the Python world after years of Java and PHP. While the language itself is pretty much straightforward, I'm struggling with some 'minor' issues that I can't wrap my head around — ...
18
votes
1answer
872 views

What are the problems python 3 new features solve? [closed]

Python 3 new features say: we’re mostly fixing well-known annoyances and warts, and removing a lot of old cruft It mentions what is different (the fix) but not why (the problems). I have have ...
17
votes
5answers
35k views

Why is Python slower than Java but faster than PHP [closed]

I have many times seen various benchmarks that show how a bunch of languages perform on a given task. These benchmarks always reveal that Python is slower than Java, and faster than PHP, and I wonder ...
17
votes
7answers
9k views

Would Python be too slow for client-side use in Browsers?

I've heard the statement that Python would be too slow to be of any use in browsers. I reckon Javascript is only superior in this aspect because of companies like Google who need it fast (and made it ...
17
votes
4answers
1k views

Is the benefit of the IO monad pattern for handling side effects purely academic?

Sorry for yet another FP + side effects question, but I couldn't find an existing one which quite answered this for me. My (limited) understanding of functional programming is that state/side effects ...
16
votes
6answers
9k views

How can I prevent a client from seeing my code written in an interpreted language?

I'm building a fairly complex interpreted program in Python. I've been working on most of this code for other purposes for a few months, and therefore don't want my client to be able to simply copy ...
16
votes
10answers
8k views

Preferring Python over C for Algorithmic Programming

I've been studying a bit of algorithms and have been looking at sites like SPOJ.pl TopCoder etc. I've seen that programmers prefer C or C++ usually for most algorithmic programming contests. Now I'...
16
votes
11answers
17k views

Why is Python recommended as an entry level programming language? [closed]

I've read here on P.SE more questions in which beginner programmers are advised to pick Python as their first programming language. Don't get me wrong, I like Python. I like it a lot! But its ...
16
votes
5answers
8k views

What should a Python developer know while learning Ruby? [closed]

I have been a Python programmer for about 18 months, consisting of one internship and a few side projects, and I consider myself pretty comfortable in the language. However, there seems to be a lot ...
16
votes
2answers
7k views

Should serialization and deserialization be the responsibility of the class being serialized?

I'm currently in the (re)design phase of several model classes of a C# .NET application. (Model as in M of MVC). The model classes already have plenty of well-designed data, behaviors, and ...
16
votes
5answers
8k views

Algorithm for flattening overlapping ranges

I am looking for a nice way of flattening (splitting) a list of potentially-overlapping numeric ranges. The problem is very similar to that of this question: Fastest way to split overlapping date ...
16
votes
4answers
2k views

Strategy for keeping up with (Python) language changes

Writing code that will still run years from now Programming languages change. Libraries change. Some code from 5, 10, or even 20 years ago might still run and produce expected results, whereas some ...
16
votes
2answers
2k views

Creating nested functions for purely aesthetic reasons?

I've always wondered what other programmers think about the idea of creating pure aesthetic functions. Say I have a function that processes a chunk of data: Function ProcessBigData. Say I need ...
15
votes
6answers
3k views

How to implement float hashing with approximate equality

Let's say we have the following Python class (the problem exists in Java just the same with equals and hashCode) class Temperature: def __init__(self, degrees): self.degrees = degrees ...
15
votes
4answers
4k views

Why do some programmers categorize C, Python, C++ differently? - regarding level

I am taking an introductory course on python and the instructor says that python is a high level language and C and C++ are low level languages. It's just confusing. I thought that C, C++, Python, ...
15
votes
5answers
6k views

Is monkeypatching considered good programming practice?

I've been under impression, that monkeypatching is more in quick and dirty hack category, rather than standard, good programming practice. While I'd used from time to time to fix minor issues with 3rd ...
15
votes
2answers
15k views

What are hooks? [closed]

I keep coming across this term hooks in various programming articles. However I don't understand what they are, and how can they be used. So I just wanted to know what is the concept of hooks; if ...
15
votes
1answer
11k views

Why did Microsoft abandon IronRuby and IronPython? [closed]

Several years ago, Microsoft announced that Ruby and Python were coming to .net. The projects were called IronRuby and IronPython, respectively. Microsoft said that the projects would be built on ...
15
votes
4answers
15k views

Returning a boolean when success or failure is the sole concern

I often find myself returning a boolean from a method, that's used in multiple locations, in order to contain all the logic around that method in a single place. All the (internal) calling method ...
15
votes
2answers
2k views

Many small scripts, one repository or multiple?

A co-worker and myself have run into an issue that we have multiple opinions on. Currently we have a git repository that we are keeping all of our cronjobs in. There are about 20 crons and they are ...
15
votes
1answer
1k views

How can I tell if I am overusing multi-threading?

I currently feel like I am over-using multi-threading. I have 3 types of data, A, B and C. Each A can be converted to multiple Bs and each B can be converted to multiple Cs. I am only interested in ...
14
votes
9answers
24k views

Python: Future as a major programming language? [closed]

After reading some Python material and seeing some Python code a few years back I decided to give it a whirl. I decided to start with Python to solve the problems on Project Euler and was throughly ...
14
votes
2answers
1k views

Design decision - why generate <p> without </p>?

tl;dr Some widely used programs, which generate html, will only generate opening paragraph tags, and not closing ones, assuming that the browser will properly close paragraphs. On the face of it, it ...
14
votes
2answers
6k views

Are exceptions for flow control best practice in Python?

I'm reading "Learning Python" and have come across the following: User-defined exceptions can also signal nonerror conditions. For instance, a search routine can be coded to raise an exception ...
14
votes
5answers
614 views

How should someone used to FP thinking read imperative code?

I graduated from university about five months ago, and have been working in a local startup for past four months. While at university, I studied Haskell, F# etc on my own. We were taught Java at the ...
14
votes
5answers
2k views

Is a well written documentation a good enough reason for learning a programming language? [closed]

I am learning Python currently which wasn't part of my college curriculum. I was asked in an interview why I chose Python and I replied that it is easy to learn and the documentation is very well ...
14
votes
2answers
2k views

Is **kwargs an antipattern?

We have a lot of code in our internal codebase that calls our libraries internally - these libraries often have a lot of arguments (think matplotlib) and our code is often doing only a specific task ...
14
votes
5answers
4k views

Coming up with tokens for a lexer

I'm writing a parser for a markup language that I have created (writing in python, but that's not really relevant to this question -- in fact if this seems like a bad idea, I'd love a suggestion for a ...
14
votes
1answer
1k views

Is Windows a “second class citizen” in the Django community?

I'm currently doing R&D for a web application which we plan to host ourselves initially and then allow customers to self host. My task has been evaluating web frameworks to see which would give ...
13
votes
2answers
16k views

Debug multiprocessing in Python

What are some good practices in debugging multiprocessing programs in Python?
13
votes
5answers
13k views

When should use of database be preferred over parsing data from a text file?

I was making a Python program to measure the growth of codereview.SE. My approach was to get the "Site stats" shown on the front page and store them on my hard drive. I plan to do this once every day. ...
13
votes
8answers
3k views

Choosing between CL and Python for web development

I'm coming from a Java background and after I read this little essay by Paul Graham I started wondering about picking up a new language namely Common Lisp to speed up my work (I'm a web developer). I'...
13
votes
2answers
2k views

Object oriented vs vector based programming

I am torn between object oriented and vector based design. I love the abilities, structure and safety that objects give to the whole architecture. But at the same time, speed is very important to me, ...
13
votes
2answers
977 views

Early attempt to remove Python GIL resulted in bad performance: Why?

This post from Python creator, Guido Van Rossum, mentions an early attempt to remove the GIL from Python: This has been tried before, with disappointing results, which is why I'm reluctant to put ...
12
votes
3answers
2k views

Working through the single responsibility principle (SRP) in Python when calls are expensive

Some base points: Python method calls are "expensive" due to its interpreted nature. In theory, if your code is simple enough, breaking down Python code has negative impact besides readability and ...
12
votes
3answers
21k views

Python - assert vs if & return

I am writing a script that does something to a text file (what it does is irrelevant for my question though). So before I do something to the file I want to check if the file exists. I can do this, no ...
12
votes
4answers
1k views

Do you think that GAE alone is enough to justify learning Python over Ruby? [closed]

Considering the fact that you don't have to get involved in setting up/buying a server or even buying a domain, do you think that fact alone is enough to choose one over the other? I don't ...