Top "Python-2.x" questions

For questions about Python programming that are specific to version 2.x of the language.

Malformed String ValueError ast.literal_eval() with String representation of Tuple

I'm trying to read in a string representation of a Tuple from a file, and add the tuple to a …

python parsing python-2.x abstract-syntax-tree representation
Python: Using .format() on a Unicode-escaped string

I am using Python 2.6.5. My code requires the use of the "more than or equal to" sign. Here it goes: &…

python string unicode python-2.x
How can I concatenate str and int objects?

If I try to do the following: things = 5 print("You have " + things + " things.") I get the following error in Python 3.…

python string python-3.x concatenation python-2.x
Parsing HTML to get text inside an element

I need to get the text inside the two elements into a string: source_code = """<span class="UserName">&…

python html python-2.x html-parser
Is it possible to run python SimpleHTTPServer on localhost only?

I have a vpn connection and when I'm running python -m SimpleHTTPServer, it serves on 0.0.0.0:8000, which means it can be …

python http command-line python-2.x simplehttpserver
TypeError: super() takes at least 1 argument (0 given) error is specific to any python version?

I'm getting this error TypeError: super() takes at least 1 argument (0 given) using this code on python2.7.11: class Foo(object): def __…

python python-2.7 python-2.x
How to handle a broken pipe (SIGPIPE) in python?

I've written a simple multi-threaded game server in python that creates a new thread for each client connection. I'm finding …

python python-2.x broken-pipe
How to check if variable is string with python 2 and 3 compatibility

I'm aware that I can use: isinstance(x, str) in python-3.x but I need to check if something is …

python string python-3.x python-2.x
How does Python 2 compare string and int? Why do lists compare as greater than numbers, and tuples greater than lists?

The following snippet is annotated with the output (as seen on ideone.com): print "100" < "2" # True print "5" > "9" # False print "100" &…

python types comparison python-2.x
Why does Python print unicode characters when the default encoding is ASCII?

From the Python 2.6 shell: >>> import sys >>> print sys.getdefaultencoding() ascii >>> print …

python unicode encoding ascii python-2.x