Thomas Jollans wrote:
> On 19/07/11 06:42, Steven D'Aprano wrote:
>> (1) Escape every backslash with an extra backslash:
>>
>>>>> print "logs\\2011-07-03"
>> logs\2011-07-03
>
> There is a more elegant solution: use raw strings: r'c:\foo\bar'
Well, perhaps, but not all paths can be written as a raw string:
>>> path = r'a\b\c\'
File "<stdin>", line 1
path = r'a\b\c\'
^
SyntaxError: EOL while scanning single-quoted string
>> (2) Use forward slashes, as Windows will happily accept them instead of
>> backslashes.
>
> The "correct" solution in many cases is to not assume any particular
> path separator at all, and use os.path.join when dealing with paths.
> This will work even on systems that do not accept forward slashes as
> path separators. (does Python still support any of those?)
Yes, but only just. Python still includes support for VMS, at least for now;
support is scheduled to be dropped in 3.3 and code supporting it to be
removed in 3.4.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list