This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.abspath in window7, return error
Type: behavior Stage:
Components: Windows Versions: Python 2.7
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, xiaowei.py
Priority: normal Keywords:

Created on 2013-02-28 11:21 by xiaowei.py, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg183212 - (view) Author: xiaowei (xiaowei.py) Date: 2013-02-28 11:21
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.*
msg184401 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2013-03-17 22:02
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())
msg184583 - (view) Author: xiaowei (xiaowei.py) Date: 2013-03-19 03:19
thank you
os: win7 bit64
python: 2.7.3

>>> import sys,locale
>>> print(locale.getdefaultlocale())
('zh_CN', 'cp936')
>>> print(sys.getdefaultencoding())
ascii
>>>

祝愉快!

肖微

  2013年  月  日

2013/3/18 Amaury Forgeot d'Arc <report@bugs.python.org>

>
> Amaury Forgeot d'Arc added the comment:
>
> 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())
>
> ----------
> nosy: +amaury.forgeotdarc
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue17320>
> _______________________________________
>
msg184630 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2013-03-19 10:54
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.
History
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61522
2013-04-16 07:46:03xiaowei.pysetstatus: open -> closed
2013-03-19 10:54:29amaury.forgeotdarcsetmessages: + msg184630
2013-03-19 03:19:55xiaowei.pysetmessages: + msg184583
2013-03-17 22:02:16amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg184401
2013-02-28 11:21:01xiaowei.pycreate