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 [quote] 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 R:\>%dir1%\hello.bat hello world R:\>%dir2%\hello.bat 'R:\just' is not recognized as an internal or external command [/quote] Then, in python (it seems to be a common problem in all(?) python version) [quote] 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('"', ''))) [/quote] displays [quote] "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 True ********** R:\just a test True True [/quote] the patched method is simple [quote] if os.name=='nt': res=res.replace('"', '') [/quote] 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 <rep...@bugs.python.org> <http://bugs.python.org/issue24461> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com