python-2.4

How to safely open/close files in python 2.4

北城余情 提交于 2019-11-26 08:14:18
问题 I\'m currently writing a small script for use on one of our servers using Python. The server only has Python 2.4.4 installed. I didn\'t start using Python until 2.5 was out, so I\'m used to the form: with open(\'file.txt\', \'r\') as f: # do stuff with f However, there is no with statement before 2.5, and I\'m having trouble finding examples about the proper way to clean up a file object manually. What\'s the best practice for disposing of file objects safely when using old versions of python

Unpickling a python 2 object with python 3

冷暖自知 提交于 2019-11-26 02:52:35
问题 I\'m wondering if there is a way to load an object that was pickled in Python 2.4, with Python 3.4. I\'ve been running 2to3 on a large amount of company legacy code to get it up to date. Having done this, when running the file I get the following error: File \"H:\\fixers - 3.4\\addressfixer - 3.4\\trunk\\lib\\address\\address_generic.py\" , line 382, in read_ref_files d = pickle.load(open(mshelffile, \'rb\')) UnicodeDecodeError: \'ascii\' codec can\'t decode byte 0xe2 in position 1: ordinal