Encoding of file names

utabintarbo utabintarbo at gmail.com
Thu Dec 8 18:48:23 CET 2005


Fredrik, you are a God! Thank You^3. I am unworthy </ass-kiss-mode>

I believe that may do the trick. Here is the results of running your
code:

>>> DIR = os.getcwd()
>>> files = os.listdir(DIR)
>>> file = files[-1]
>>> file
'L07JS41C.04389525AA.QTR\xa6INR.E\xa6C-P.D11.081305.P2.KPF.model'
>>> print file
L07JS41C.04389525AA.QTRªINR.EªC-P.D11.081305.P2.KPF.model
>>> print repr(file)
'L07JS41C.04389525AA.QTR\xa6INR.E\xa6C-P.D11.081305.P2.KPF.model'
>>> fullname = os.path.join(DIR, file)
>>> print os.path.isfile(fullname)
False
>>> print os.path.isdir(fullname)
False
>>> files = os.listdir(unicode(DIR))
>>> file = files[-1]
>>> print file
L07JS41C.04389525AA.QTR¦INR.E¦C-P.D11.081305.P2.KPF.model
>>> print repr(file)
u'L07JS41C.04389525AA.QTR\u2592INR.E\u2524C-P.D11.081305.P2.KPF.model'
>>> fullname = os.path.join(DIR, file)
>>> print os.path.isfile(fullname)
True                                             <--- Success!
>>> print os.path.isdir(fullname)
False

Thanks to all who posted. :-)




More information about the Python-list mailing list