Python is a dynamic, high-level 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, exceptions, had an extensive standard module library. Python can also be embedded in other ...
137
votes
9answers
32k views
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 ...
102
votes
15answers
16k views
Is it always a best practice to write a function for anything that needs to repeat twice?
For myself, I can't wait to write a function when I need to do something more than twice. But when it comes to the things that only appear twice, it's a bit more tricky.
For code that needs more than ...
74
votes
9answers
38k views
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++, ...
71
votes
8answers
10k views
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 ...
70
votes
6answers
8k views
Why was Python's popularity so sudden? [closed]
Python first appeared in 1991, but it was somewhat unknown until 2004, if the TIOBE rankings quantify anything meaningful.
What happened? What caused the interest in this 13 year old language to go ...
60
votes
5answers
72k views
R vs Python for data analysis [closed]
I have been programming for about a year and I am really interested in data analysis and machine learning. I am taking part in a couple of online courses and am reading a couple of books.
Everything ...
54
votes
7answers
37k views
Why use try … finally without a catch clause?
The classical way to program is with try ... catch. When is it appropriate to use try without catch?
In Python the following appears legal and can make sense:
try:
#do work
finally:
#do ...
49
votes
7answers
55k views
How do I learn Python from zero to web development? [closed]
I am looking into learning Python for web development.
Assuming I already have some basic web development experience with Java (JSP/Servlets), I'm already familiar with web design (HTML, CSS, JS), ...
46
votes
8answers
9k views
Defensive Programming 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: Defensive coding vs Exception handling. Here ...
41
votes
13answers
9k views
How does Python's handling of line-breaks differ from JavaScript's automatic semicolons?
Javascript has a feature called Automatic Semicolon Insertion where basically if the parser encounters an invalid token, and the last token before that was a line break, then the parser will insert a ...
41
votes
4answers
5k views
Experience of Python's “PEP-302 New Import Hooks”
I'm one of the developers of Ruby (CRuby). We are working on Ruby 2.0 release (planned to release 2012/Feb).
Python has "PEP302: New Import Hooks" (2003):
This PEP proposes to add a new set of ...
41
votes
1answer
22k views
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?
40
votes
13answers
5k views
Is C# development effectively inseparable from the IDE you use?
I'm a Python programmer learning C# who is trying to stop worrying and just love C# for what it is, rather than constantly comparing it back to Python.
I'm caught up on one point: the lack of ...
39
votes
8answers
8k views
How can I learn to effectively write Pythonic code?
Doing a google search for "pythonic" reveals a wide range of interpretations. The wikipedia page says:
A common neologism in the Python community is pythonic, which can have a wide range of ...
38
votes
7answers
4k views
Are small amounts of functional programming understandable by non-FP people?
Case: I'm working at a company, writing an application in Python that is handling a lot of data in arrays. I'm the only developer of this program at the moment, but it will probably be ...
37
votes
2answers
4k views
How do I move away from the “for-loop” school of thought?
This is a rather conceptual question, but I was hoping I could get some good advice on this. A lot of the programming I do is with (NumPy) arrays; I often have to match items in two or more arrays ...
36
votes
16answers
25k views
Why such popularity with Python? [closed]
Other than being annoyed at whitespace as syntax, I'm not a hater, I just don't get the fascination with Python.
I appreciate the poetry of Perl, and have programmed beautiful web services in bash ...
33
votes
3answers
3k views
Python Forgiveness vs. Permission and Duck Typing
In Python, I often hear that it is better to "beg forgiveness" (exception catching) instead of "ask permission" (type/condition checking). In regards to enforcing duck typing in Python, is this
try:
...
32
votes
2answers
18k views
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 ...
32
votes
5answers
3k views
Java dev learning Python: what concepts do I need to wrap my head around?
I've run through a few tutorials and written some small projects. I'm right in the middle of a small project now infact. All is going well enough thanks in no small part to Uncle Google (who usually ...
30
votes
6answers
4k views
Why aren't there other programming languages that compile to Python bytecode?
In Java, there are multiple languages that compile to Java bytecode and can run on the JVM -- Clojure, Groovy, and Scala being the main ones I can remember off the top of my head.
However, Python ...
29
votes
3answers
24k views
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 ...
29
votes
6answers
20k views
'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 ...
29
votes
1answer
1k views
How to deal with a misnamed function in production code?
I've recently come across a Python library on GitHub. The library is great, but contains one glaring typo in a function name. Let's call it dummy_fuction() while it should be dummy_function(). This ...
28
votes
8answers
5k views
Is the algorithm more important than the programming language?
During the current (2013) Google Code Jam contest, there was a problem that took C++ and Java people 200+ lines of code as compared to Python people that solved the same problem only using 40 lines of ...
28
votes
4answers
20k views
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 ...
27
votes
4answers
3k views
Concrete examples of Python's “only one way to do it” maxim
I am learning Python and am intrigued by the following point in PEP 20 The Zen of Python:
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be ...
25
votes
6answers
12k views
Programming language usage at Google [closed]
I have heard Google uses Python, Java and C++. But what I don't know is how is each of those programming language is used. I mean what is Python, Java and C++ is used for at Google. Why would they ...
25
votes
4answers
5k views
Should I stick with or abandon Python to deal with concurrency?
I have a 10K LOC project written in Django with quite a deal of Celery (RabbitMQ) for asynchronicity and background jobs where needed, and have come to the conclusion that parts of the system would ...
24
votes
8answers
2k views
Do frameworks put too much abstraction? [closed]
I've been programming for a little under a year and have some experience writing systems applications, web apps, and scripts for businesses/organizations. However, one thing I've never really done is ...
23
votes
3answers
10k views
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?"
...
23
votes
7answers
18k views
Should we use python 2.6 or 2.7 or 3.x? [closed]
The version of python which I am using is 2.6, and there is a 2.7 and 3.x. Usually I use python for some trivial program/snippet. I realize there are some major difference between 2.x and 3.x. I would ...
23
votes
6answers
3k views
Functional programming compared to OOP with classes
I have been interested in some of the concepts of functional programming lately. I have used OOP for some time now. I can see how I would build a fairly complex app in OOP. Each object would know how ...
23
votes
5answers
7k views
Is programming in Python faster than in C, C++ or Java?
There's a widespread belief among programmers that the more dynamic and loosely typed the language, the more productive the programmer will be in it. Guido van Rossum wrote about programming ...
22
votes
8answers
18k views
Ruby or Python? [closed]
This question is extremely subjective and open-ended. It might even sound like something I should just research for myself and make my own decision. But I'd like to put it out there and get some ...
22
votes
4answers
10k views
Why do iterators in Python raise an exception?
Here's the syntax for iterators in Java (somewhat similar syntax in C#):
Iterator it = sequence.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
Which makes sense. Here's ...
21
votes
4answers
26k views
Is Python Interpreted or Compiled?
This is just a wondering I had while reading about interpreted and compiled languages.
Ruby is no doubt an interpreted language, since source code is compiled by an interpreter at the point of ...
21
votes
3answers
4k views
Why aren't there explicit access modifiers in Python:
If 'explicit is better than implicit', why aren't there explicit access modifiers in Python: Public, Protected, Private, etc.?
I know that the idea is that the programmer should know what to do ...
20
votes
11answers
4k views
If we can do functional programming with Python, do we need a specific functional programming language? [closed]
Using generators and lambda, we can do functional programming with Python. You can also achieve the same thing with Ruby.
So the question is: why do we need specific functional programming languages ...
20
votes
5answers
2k views
Will Python 3.0's backwards-incompatibility affect adoption?
I visited Slashdot this morning to find out that Python 3.0 has been released. I know C# and Perl, but have wanted to learn Python for some time, especially after I saw its ease of use to create ...
20
votes
3answers
777 views
How do I express subtle relationships in my data?
"A" is related to "B" and "C". How do I show that "B" and "C" might, by this context, be related as well?
Example:
Here are a few headlines about a recent Broadway play:
David Mamet's Glengarry ...
19
votes
7answers
5k views
Learning to program in C (coming from Python) [closed]
If this is the wrong place to ask this question, please let me know.
I'm a Python programmer by occupation. I would love to learn C. Indeed, I have tried many times, but I always get discouraged. In ...
19
votes
3answers
1k views
Why do so many languages treat numbers starting with 0 as octal?
I've read Where are octals useful? and it seems like octals are something that were once upon a time useful.
Many languages treat numbers preceding with a 0 as octal, so the literal 010 is actually ...
18
votes
6answers
3k views
Advantage of Learning Lisp for a Python Programmer
I am primarily a Python, Java, C++ programmer, and I've gained a recent interest in functional language. I'm thinking of picking up a LISP dialect: Clojure. Now, I've been working through tutorials ...
18
votes
9answers
7k views
Is it essential to learn algorithms to be a real programmer? [closed]
I'm a PHP programmer, and until now I have not needed to learn algorithms...
Now I'm start learning Python (a real programming language), because I need to use matplotlib. Does it make sense to start ...
18
votes
5answers
2k views
What does Tim Peters mean by “complex is better than complicated”? [closed]
In Tim Peters's poem "The Zen of Python" (PEP 20), there is a line that goes:
Complex is better than complicated.
I like the theme of the poem, but this particular line has always vexed me. What ...
18
votes
3answers
2k views
Should I pass in filenames to be opened, or open files?
Suppose I have a function that does things with a text file - for example reads from it and removes the word 'a'. I could either pass it a filename and handle the opening/closing in the function, or ...
18
votes
4answers
2k views
Are there any negative side effects of splitting up large modules? [closed]
I was browsing a github project and found this module which has more than 10 thousand lines.
Is it a common practice to have that much code in a single module?
It seems to me that this should be ...
17
votes
18answers
2k views
How do I “ease into” programming coming from a designer background?
Is there a way I can 'ease in' to programming. Like learning to use/modify CGI scripts to add some functions to a basic html site? Even if it's the only thing I learn it's still useful, right?. Unlike ...
17
votes
3answers
3k views
How to solve the problem of nested comments
It appears in not just one language that comments can't be nested. Do you have a good solution for this problem? One workaround in C/C++ and Java is to only use the single-line comment but it becomes ...