开发者

A super strange bug of os.path.abspath

On My Python 2.6 ( 64bit, win7, ActivePython ), when i call: os.path.abspath('D:/PROJECTS/SuiShouBei/www/ssb/static/voices/en/mp3/con.mp3')

It returns:

'\\\\.\\con'

I have no problem with other paths so far.

Anyone has the sam开发者_开发知识库e issue?

Can someone please tell me why?


I can reproduce this in Python 2.6, 2.7, 3.1 and 3.2.

The reason for this behavior is the fact that CON is an illegal filename in Windows (try os.path.abspath('D:/PROJECTS/SuiShouBei/www/ssb/static/voices/en/mp3/cont.mp3') and see that everything works fine).

So take care that your filenames don't contain

< (less than)
> (greater than)
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)

Also do not use the following reserved device names for the name of a file (with or without extension):

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, 
LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. 

As noticed by slowdog, it is mentioned in the same MSDN document as above that \\.\CON is the correct way to access such a device name directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜