Mailing List Archive

[issue5098] Environ doesn't escape spaces properly
New submission from Stuart Axon <stu.axon@gmail.com>:

os.environ doesn't escape spaces, but does backslashes and others

In the windows python interpreter I echo'd the variable 'ProgramFiles',
then in the commandprompt.

>>> from os import environ
>>> environ['ProgramFiles']
'C:\\Program Files'
>>> ^Z

[C:\]echo %ProgramFiles%
C:\Program Files

This 'half' escapping seems odd, and is annoying when building file
paths for instance, probably the space should also be escaped.

----------
components: None
messages: 80765
nosy: stuaxo
severity: normal
status: open
title: Environ doesn't escape spaces properly
type: behavior
versions: Python 2.5

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5098>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5098] Environ doesn't escape spaces properly [ In reply to ]
Jean-Paul Calderone <exarkun@divmod.com> added the comment:

The backslash escaping has nothing to do with os.environ. It's the way
any string with a backslash in it is displayed in the interactive
interpreter (it's the way str.__repr__ works). Performing any escaping
on a string to make it usable in a command line is a task which is
inappropriate as a feature of os.environ. The contents of os.environ
are just strings. If you want to use them in a command line, you need
to escape them appropriately. Notice that in addition to escaping the
space, you may also sometimes need to escape a backslash (not in this
case on Windows, though, since a single \ is allowed here). The
escaping of the \ in this example is *only* in the *display* of the
variable - there is only one \ in the string itself.

I recommend closing this ticket as invalid.

----------
nosy: +exarkun

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5098>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5098] Environ doesn't escape spaces properly [ In reply to ]
Martin v. Löwis <martin@v.loewis.de> added the comment:

As Jean-Paul explains, you are misinterpreting what you are seeing.
Closing as invalid.

----------
nosy: +loewis
resolution: -> invalid
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5098>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com