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.
Questions tagged [python]
1966 questions
294
votes
2 answers
Python file naming convention?
I've seen this part of PEP-8 https://www.python.org/dev/peps/pep-0008/#package-and-module-names
I'm not clear on whether this refers to the file name of a module/class/package.
If I had one example of each, should the filenames be all lower case…

darkace
- 3,051
- 3
- 10
- 5
230
votes
9 answers
Why do people hesitate to use Python 3?
Python 3 was released in December 2008. A lot of time has passed since then but still today many developers hesitate to use Python 3. Even popular frameworks like Django are not compatible with Python 3 yet but still rely on Python 2.
Sure, Python 3…

Ham Vocke
- 2,467
- 2
- 15
- 8
219
votes
8 answers
'import module' vs. 'from module import function'
I have always been using this method:
from sys import argv
and use argv with just argv. But there is a convention of using this:
import sys
and using the argv by sys.argv
The second method makes the code self documented and I (really) adhere to…

Santosh Kumar
- 2,261
- 4
- 15
- 21
172
votes
23 answers
Programming cleanly when writing scientific code
I don't really write large projects. I'm not maintaining a huge database or dealing with millions of lines of code.
My code is primarily "scripting" type stuff - things to test mathematical functions, or to simulate something - "scientific…

Auden Young
- 1,637
- 3
- 11
- 21
159
votes
1 answer
Module vs. Package?
Whenever I do from 'x' import 'y' I was wondering which one is considered the 'module' and which is the 'package', and why it isn't the other way around?

Dark Templar
- 6,223
- 16
- 46
- 46
147
votes
24 answers
What are the drawbacks of Python?
Python seems all the rage these days, and not undeservingly - for it is truly a language with which one almost enjoys being given a new problem to solve. But, as a wise man once said (calling him a wise man only because I've no idea as to who…

Rook
- 19,861
- 9
- 53
- 96
137
votes
3 answers
Why Was Python Written with the GIL?
The global interpreter lock (GIL) seems to be often cited as a major reason why threading and the like is a touch tricky in Python - which raises the question "Why was that done in the first place?"
Being Not A Programmer, I've got no clue why that…

Fomite
- 2,616
- 6
- 18
- 20
135
votes
15 answers
Is it always a best practice to write a function for anything that needs to repeat twice?
Myself, I can't wait to write a function when I need to do something more than twice. But when it comes to things that only appear twice, it's a bit more tricky.
For code that needs more than two lines, I'll write a function. But when facing things…

Zen
- 1,693
- 2
- 13
- 12
119
votes
2 answers
What's wrong with relative imports in Python?
I recently upgraded versions of pylint, a popular Python style-checker.
It has gone ballistic throughout my code, pointing out places where I import modules in the same package, without specifying the full package path.
The new error message is…

Oddthinking
- 1,732
- 2
- 12
- 14
108
votes
10 answers
Why is Python used for high-performance/scientific computing (but Ruby isn't)?
There's a quote from a PyCon 2011 talk that goes:
At least in our shop (Argonne National Laboratory) we have three
accepted languages for scientific computing. In this order they are
C/C++, Fortran in all its dialects, and Python. You’ll notice…

Cyclops
- 2,167
- 3
- 17
- 20
107
votes
8 answers
Are there any design patterns that are unnecessary in dynamic languages like Python?
I've started reading the design pattern book by the GoF. Some patterns seem very similar with only minor conceptual differences.
Do you think out of the many patterns some are unnecessary in a dynamic language like Python (e.g. because they are…

Gere
- 2,191
- 2
- 17
- 21
104
votes
9 answers
Check First vs Exception Handling?
I'm working through the book "Head First Python" (it's my language to learn this year) and I got to a section where they argue about two code techniques:
Checking First vs Exception handling.
Here is a sample of the Python code:
# Checking First
for…

jmq
- 6,048
- 5
- 28
- 39
101
votes
3 answers
Why is Python written in C and not in C++?
In Python's tutorial one can read that Python's original implementation is in C;
On the other hand, the Python implementation, written in C, (...)
I'm very curious why was Python written in C and not C++?
I'd like to know the reasoning behind…

Piotr Dobrogost
- 1,145
- 2
- 8
- 10
96
votes
5 answers
Why is %s better than + for concatenation?
I understand that we should use %s to concatenate a string rather than + in Python.
I could do any of:
hello = "hello"
world = "world"
print hello + " " + world
print "%s %s" % (hello, world)
print "{} {}".format(hello, world)
print '…

Niklas Rosencrantz
- 8,008
- 17
- 56
- 95
96
votes
5 answers
Why store a function inside a python dictionary?
I'm a python beginner, and I just learned a technique involving dictionaries and functions. The syntax is easy and it seems like a trivial thing, but my python senses are tingling. Something tells me this is a deep and very pythonic concept and I'm…

mdeutschmtl
- 1,079
- 1
- 8
- 6