assert os.path.split( os.path.abspath('\xe7\x8e\xb0' ) )[-1] == '\xe7\x8e\xb0' # it should be true(no error) but py2.7 in window it's false # and when linux it's ok # os.path.split( os.path.abspath('\xe7\x8e\xb0' ) )[-1] == '\xe7\x8e' # i guess it's a real bug , hope some one can resolve it # i donot try py3.* , i donot know if it exists in 3.*
There may be an issue with the GetFullPathName system call. Could you copy the result of these functions: import sys, locale print(locale.getdefaultlocale()) print(sys.getdefaultencoding())
The string '\xe7\x8e\xb0' is the utf-8 encoded version of u'现' (=u'\u73b0') But your Windows system uses the cp936 code page to encode file names. '\xe7\x8e\xb0' is invalid in this code page: the last character is an incomplete multibyte sequence, and is dropped by Windows when converting to a Unicode file name. Windows automatic conversion functions work similar to this Python code (note the 'ignore' parameter): >>> '\xe7\x8e\xb0'.decode('cp936', 'ignore').encode('cp936') '\xe7\x8e' '\xe7\x8e\xb0' is an invalid file name on your platform. You should either: - use cp936 encoding in your application - much better, use unicode file names everywhere: >>> os.path.abspath('\xe7\x8e\xb0'.decode('utf-8')) will return the expected result. Python3 will emit a Warning when os.path.abspath() is called with a bytes string.