In the Python in the 2.x series Python 2.7 is the latest, and last, major release.

learn more… | top users | synonyms

85
votes
1answer
3k views

Why is early return slower than else?

This is a follow-up question to an answer I gave a few days back. Edit: it seems that the OP of that question already used the code I posted to him to ask the same question, but I was unaware of it. ...
76
votes
2answers
2k views

str performance in python

While profiling a piece of python code (python 2.6 up to 3.2), I discovered that the str method to convert an object (in my case an integer) to a string is almost an order of magnitude slower than ...
64
votes
1answer
2k views

Python: why are * and ** faster than / and sqrt()?

While optimising my code I realised the following: >>> from timeit import Timer as T >>> T(lambda : 1234567890 / 4.0).repeat() [0.22256922721862793, 0.20560789108276367, ...
39
votes
3answers
37k views

How to uninstall Python 2.7 on a Mac OS X 10.6.4?

I want to completely remove Python 2.7 from my Mac OS X 10.6.4. I managed to remove the entry from the PATH variable by reverting my .bash_profile. But I also want to remove all directories, files, ...
28
votes
5answers
2k views

Python: What's the difference between __builtin__ and __builtins__?

I was coding today and noticed something. If I open a new interpreter session (IDLE) and check what's defined with the dir function I get this: $ python >>> dir() ['__builtins__', '__doc__', ...
19
votes
4answers
8k views

Why is parenthesis in print voluntary in Python 2.7?

In Python 2.7 both the following will do the same print("Hello, world!") # Prints "Hello, world!" print "Hello, world!" # Prints "Hello, world!" However the following will not print("Hello,", ...
19
votes
3answers
949 views

Python — what is NOT in 2.7 that IS in 3.1? So many things have been back-ported, what is NOT?

I've been following the saga of Python 3.x and have watched the 3.x features gradually getting back-ported to the 2.x line. Most of the libraries I use haven't been ported and some (e.g. Twisted) ...
19
votes
4answers
2k views

What is the cross-platform method of enumerating serial ports in Python (including virtual ports)?

Note: I'm using Python 2.7, and pySerial for serial communications. I found this article which lists two ways: http://www.zaber.com/wiki/Software/Python#Displaying_a_list_of_available_serial_ports ...
18
votes
7answers
448 views

Constructing the largest number possible by rearranging a list

Say I have an array of positive whole integers; I'd like to manipulate the order so that the concatenation of the resultant array is the largest number possible. For example [97, 9, 13] results in ...
18
votes
1answer
458 views

Huge memory leak in repeated os.path.isdir calls?

I've been scripting something that has to do with scanning directories and noticed a severe memory leak when calling os.path.isdir, so I've tried the following snippet: def func(): if not ...
17
votes
13answers
941 views

What is the fastest way to the delete lines in a file which have no match in a second file?

I have two files, wordlist.txt and text.txt. The first file, wordlist.txt, contains a huge list of words in Chinese, Japanese, and Korean, e.g.: 你 你们 我 The second file, text.txt, contains long ...
16
votes
6answers
595 views

Does this prime function actually work?

Since I'm starting to get the hang of Python, I'm starting to test my newly acquired Python skills on some problems on projecteuler.net. Anyways, at some point, I ended up making a function for ...
15
votes
4answers
12k views

gcc-4.2 failed with exit status 1

I've been looking for an answer to this issue but I couldn't find it, so here it is. I'm trying to install Uniconvertor with a setup.py file into a MacOS X Lion (Python 2.7.2) using: python setup.py ...
15
votes
3answers
844 views

memoization library for python 2.7

I see that python 3.2 has memoization as a decorator in functools library. http://docs.python.org/py3k/library/functools.html#functools.lru_cache Unfortunately it is not yet backported to 2.7. Is ...
14
votes
2answers
18k views

Installing Numpy on 64bit Windows 7 with Python 2.7.3

It looks like the only 64 bit windows installer for Numpy is for Numpy version 1.3.0 which only works with Python 2.6 http://sourceforge.net/projects/numpy/files/NumPy/ It strikes me as strange that ...

1 2 3 4 5 495
15 30 50 per page