[New-bugs-announce] [issue24461] os.environ.get treats Environt variant with double quotation marks wrong

进陆 report at bugs.python.org
Wed Jun 17 11:51:02 CEST 2015

New submission from 进陆:

On windows, if a Directory/Filename has SPACE, double quotation mark should be used. For example, "R:\just a test\hello.bat" has only one line "@echo hello world", so in the dos prompt
R:\just a test>hello.bat
hello world

R:\just a test>cd ..

R:\>set dir1="R:\just a test"

R:\>set dir2=R:\just a test

hello world

'R:\just' is not recognized as an internal or external command 

Then, in python (it seems to be a common problem in all(?) python version)
dir1= os.environ.get('dir1')
print (dir1)
print (os.path.isdir(dir1))
print (os.path.isdir(dir1.replace('"', '')))

print ('*'*10)

dir2= os.environ.get('dir2')
print (dir2)
print (os.path.isdir(dir2))
print (os.path.isdir(dir2.replace('"', '')))
"R:\just a test"
False                  <--obviously, the double quotation marks is treated as the part of the directory name by python, so the answer is wrong
R:\just a test

the patched method is simple
if os.name=='nt':
    res=res.replace('"', '')
but the not simple thing is that os.py for python 3.4.3 changes a lot than os.py for python 2.7, I get lost while reading os.py for python 3.4.3 by no IDE. So I just report this issue, sorry.

components: Library (Lib)
messages: 245433
nosy: 进陆
priority: normal
severity: normal
status: open
title: os.environ.get treats Environt variant with double quotation marks wrong
type: behavior
versions: Python 2.7, Python 3.4

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list