How to unzip a file with Python 2.4?

You have to use namelist() and extract(). Sample considering directories import zipfile import os.path import os zfile = zipfile.ZipFile(“test.zip”) for name in zfile.namelist(): (dirname, filename) = os.path.split(name) print “Decompressing ” + filename + ” on ” + dirname if not os.path.exists(dirname): os.makedirs(dirname) zfile.extract(name, dirname)

How to make Python format floats with certain amount of significant digits?

You’ll want the g modifier for format that drops insignificant zeroes; >>> “{0:.6g}”.format(5.5657188485) ‘5.56572’ >>> “{0:.6g}”.format(3.539) ‘3.539’ Sorry, my update also includes the fact that I am restricted to using Python 2.4.3, which does not have format() function. The format specifiers work even without the .format() function: >>> for i in a: … print ‘%.6g’ … Read more

How to safely open/close files in python 2.4

See docs.python.org: When you’re done with a file, call f.close() to close it and free up any system resources taken up by the open file. After calling f.close(), attempts to use the file object will automatically fail. Hence use close() elegantly with try/finally: f = open(‘file.txt’, ‘r’) try: # do stuff with f finally: f.close() … Read more

Unpickling a python 2 object with python 3

You’ll have to tell pickle.load() how to convert Python bytestring data to Python 3 strings, or you can tell pickle to leave them as bytes. The default is to try and decode all string data as ASCII, and that decoding fails. See the pickle.load() documentation: Optional keyword arguments are fix_imports, encoding and errors, which are … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)