From: Thomas H. <th...@py...> - 2004-06-15 12:01:15
|
R.R...@ve... writes: > Hello > > if have a function which converts uft-16 to latin-1 > > import codecs > > def Uni2Latin(datei): > try: > inFile = codecs.open(datei, 'r', encoding="utf-16") > outFile = codecs.open(datei+'.txt', 'w', encoding="Latin-1") > lines = inFile.readlines() > outFile.writelines(lines) > inFile.close() > outFile.close() > return True > except: > return False > > This works fine, but if I use this func. in a program made by py2exe > this functions is not able to open a utf-16 files. > > Any advice would be appreciated Unqualified except's are bad, since they hide the error from you. If you change the code above into ... except: import traceback traceback.print_exc() ... than you would have seen the traceback when running the exe: Traceback (most recent call last): File "hello.py", line 17, in Uni2Latin File "codecs.pyc", line 569, in open LookupError: unknown encoding: utf-16 This at least gives a hint: the encodings are not included. They are imported dynamically, so you must help py2exe, either this way, to include all encodings: python setup.py py2exe -p encodings or in this way, to only include the utf-16 and Latin-1 encodings: python setup.py py2exe -i encodings.utf_16,encodings.latin_1 If you prefer to avoid the command line options (which is recommended), in your setup script you can write: setup(... options = {'py2exe': {'packages': 'encodings'}}, ...) or setup(... options = {'py2exe': {'includes': ['encodings.utf_16', 'encodings.latin_1']}}, ...) Thomas |