Encoding of file names

utabintarbo utabintarbo at gmail.com
Fri Dec 9 09:49:14 EST 2005


Part of the reason (I think) is that our CAD/Data Management system
(which produces the aforementioned .MODEL files) substitutes (stupidly,
IMNSHO) non-printable characters for embedded spaces in file names.
This is part of what leads to my consternation here.

And yeah, Windows isn't helping matters much. No surprise there. :-P

Just for s&g's, I ran this on python 2.3 on knoppix:

>>> DIR = os.getcwd()
>>> files = os.listdir(DIR)
>>> file = files[-1]
>>> print file
L07JS41C.04389525AA.QTR±INR.E´C-P.D11.081305.P2.KPF.model
>>> print repr(file)
'L07JS41C.04389525AA.QTR\xb1INR.E\xb4C-P.D11.081305.P2.KPF.model'
>>> fullname = os.path.join(DIR, file)
>>> print os.path.isfile(fullname)
True                                          <--- It works fine here
>>> 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)
'L07JS41C.04389525AA.QTR\xb1INR.E\xb4C-P.D11.081305.P2.KPF.model'
>>> fullname = os.path.join(DIR, file)
>>> print os.path.isfile(fullname)
True                                          <--- It works fine here
too!
>>> print os.path.isdir(fullname)
False
>>>

This is when mounting the same samba share in Linux. This tends to
support Tom's point re:the "non-roundtrippability" thing.

Thanks again to all.




More information about the Python-list mailing list