ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> py2exe-users
py2exe-users
[Py2exe-users] Re: utf-16
by Thomas Heller other posts by this author
Jun 15 2004 11:57AM messages near this date
[Py2exe-users] utf-16 | Re: [Py2exe-users] utf-16
R.Rossbach@[...].de 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



-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
Py2exe-users mailing list
Py2exe-users@[...].net
https://lists.sourceforge.net/lists/listinfo/py2exe-users
Thread:

Thomas Heller
David Fraser

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved