Tagged Questions
134
votes
17answers
48k views
Should I learn Python 2 before 3, or start directly from Python 3? [closed]
I would like to learn python and currently have access to some good python 2 books. However python 3 is not guaranteed to be backward compatible with python 2. If I were to learn python 2 I have to ...
43
votes
5answers
30k views
Syntax error on print with Python 3
I'm new to python and am currently lost as to why print is giving a syntax here. Hoping someone might be able to point me in the right direction. Thanks
Python 3.0.1 (r301:69561, Feb 13 2009, ...
51
votes
7answers
25k views
2
votes
2answers
825 views
Python List Index
I have experienced some problem by using a nested list in Python in the code shown bleow.
Basically, I have a 2D list contains all 0 values, I want to update the list value in a loop.
However, ...
29
votes
6answers
17k views
What is an alternative to execfile in Python 3.0?
It seems they canceled in Python 3.0 all the easy way to quickly load a script file - both execfile() and reload().
Is there an obvious alternative I'm missing?
24
votes
3answers
14k views
What's the difference between raw_input() and input() in python3.x?
What is the difference between raw_input() and input() in python3.x ?
16
votes
3answers
20k views
Py2exe for Python 3.0
I am looking for a Python3.0 version of "py2exe". I tried running 2to3 on the source for py2exe but the code remained broken.
Any ideas?
32
votes
4answers
58k views
How do I use raw_input in Python 3.1
import sys
print (sys.platform)
print (2 ** 100)
raw_input( )
I am using Python 3.1 and can't get the raw_input to "freeze" the dos pop-up. The book I'm reading is for 2.5 and I'm using 3.1
What ...
12
votes
4answers
3k views
What does python sys.intern do, and when should it be used?
I came across this question about memory management of dictionaries, which mentions the intern function. What exactly does it do, and when would it be used?
To give an example:
If I have a set ...
45
votes
8answers
8k views
__getattr__ on a module
How can implement the equivalent of a __getattr__ on a class, on a module?
Example
When calling a function that does not exist in a module's statically defined attributes, I wish to create an ...
10
votes
5answers
7k views
`xrange(2**100)` -> OverflowError: long int too large to convert to int
xrange function doesn't work for large integers:
>>> N = 10**100
>>> xrange(N)
Traceback (most recent call last):
...
OverflowError: long int too large to convert to int
...
32
votes
9answers
15k views
Can I install python 3.x and 2.x on the same computer?
I'm running windows and the shell/os automatically runs python based on the registry settings when you run a program on the command line. Will this break if I install a 2.x and 3.x version of python ...
111
votes
4answers
82k views
Convert byte array to Python string
I'm using this code to get standard output from an external program:
>>> from subprocess import *
>>> command_stdout = Popen(['ls', '-l'], stdout=PIPE).communicate()[0]
The ...
22
votes
4answers
9k 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,", ...
8
votes
6answers
9k views
How do I unescape HTML entities in a string in Python 3.1?
I have looked all around and only found solutions for python 2.6 and earlier, NOTHING on how to do this in python 3.X. (I only have access to Win7 box.)
I HAVE to be able to do this in 3.1 and ...