Problem getting a file pathname with tkFileDialog

jmdeschamps at gmail.com jmdeschamps at gmail.com
Thu Nov 9 03:29:46 EST 2006


Tim Daneliuk wrote:
> Sefyroth wrote:
> > Thanks,
> >
> > but I get this error when I try this.
> >
> > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in
> > position 12: ordinal not in range(128)
> >
> >  I had encountered it with the askdirectory method as well. Is there an
> > easy way to bypass this?
> >
> > Thanks again
>
> I believe you are running into a directory or file name that has
> non-ascii characters in it.  Python as shipped is set up to
> deal with ascii as its native encoding format.  You can change
> this by editing the "site.py" file - look in the Lib directory
> in your python installation.  Look for this code:
>
> -------------------------------
> def setencoding():
>      """Set the string encoding used by the Unicode implementation.  The
>      default is 'ascii', but if you're willing to experiment, you can
>      change this."""
>      encoding = "ascii" # Default value set by _PyUnicode_Init()
>      if 0:
>          # Enable to support locale aware default string encodings.
>          import locale
>          loc = locale.getdefaultlocale()
>          if loc[1]:
>              encoding = loc[1]
> -------------------------------
>
>
>
> Change the "if 0:" to "if 1:" and see if that doesn't fix the problem.
>
>
>
> --
> ----------------------------------------------------------------------------
> Tim Daneliuk     tundra at tundraware.com
> PGP Key:         http://www.tundraware.com/PGP/

you could also use encode("iso-8859-1") to nterpret just the printed
name such as:
print myfilename.encode("iso-8859-1")

and by the way if you wanted the file NAME you could have used
openfilename() instead of openfile()    ;-)

jean-marc




More information about the Python-list mailing list