Message11808

Author jeff.allen
Recipients Arfrever, jeff.allen, zyasoft
Date 2018-03-16.08:34:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1521189300.27.0.467229070634.issue2295@psf.upfronthosting.co.za>
In-reply-to
Content
I poked around this in 2.7.2a1 and it still fails. However, I think a fix is within reach.

>>> print os.listdir('iss2295')
['tell$py.class', 'tell.py', '\xc4\x87\xc5\x9b\xc5\xba.py', '\xe5\x9b\xb0\xe9\x9a\xbe.py']
>>> for f in os.listdir('iss2295'):
...     name, ext = f.split('.')
...     if ext=='py': print name.decode('utf-8')
...
tell
困难

We need to be on the encoding that __import__ receives as an argument. Here it is a bytes object, so what is the encoding, that of the source or the FS-encoding? A unicode should be acceptable (and is).

>>> for f in os.listdir('iss2295'):
...     name, ext = f.split('.')
...     if ext=='py': print __import__(name.decode('utf-8'))
...
<module 'tell' from 'iss2295\tell.py'>

... but then it fails. The unicode argument, provides the true file name and the module is loaded. However, the print statement fails with:

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
History
Date User Action Args
2018-03-16 08:35:00jeff.allensetmessageid: <1521189300.27.0.467229070634.issue2295@psf.upfronthosting.co.za>
2018-03-16 08:35:00jeff.allensetrecipients: + jeff.allen, zyasoft, Arfrever
2018-03-16 08:35:00jeff.allenlinkissue2295 messages
2018-03-16 08:34:59jeff.allencreate