[Tutor] listdir, ispath and unicode (followup question)

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed, 31 Jul 2002 15:04:44 -0700 (PDT)


On Wed, 31 Jul 2002, Poor Yorick wrote:

> I am running Windows 2000 English edition.  The filename contains
> cyrillic characters typed with a standard Windows 2000 IME when I
> created the file.  Here is  the result of your suggestion:
>
> filename = os.path.join(os.getcwd(), os.listdir(os.getcwd())[0])
>
>  >>> filename
> 'd:\\tmp2\\???????'
>  >>> os.stat(filename)
> Traceback (most recent call last):
>  File "<pyshell#5>", line 1, in ?
>    os.stat(filename)
> OSError: [Errno 2] No such file or directory: 'd:\\tmp2\\???????'


Hmmm... now I'm suspecting that the cyrillic characters might be making a
difference.  I did a scan through the Python Enhancement Proposal 277:

    http://www.python.org/peps/pep-0277.html

which implies that Unicode filenames might not work out-of-the-box.  If
your locale at that point where you're running the Python script isn't
Cyrillic, that can potentially cause problems.


The PEP above provides an implementation that's supposed to handle Unicode
filenames properly, without the intermediate LOCALE translation stuff; can
you see if this works for you?  Sorry about the roundabout way of
answering your question.