<html>
<body>
At 05:33 PM 2/3/2011, Westley Martínez wrote:<br>
<blockquote type=cite class=cite cite="">On Thu, 2011-02-03 at 23:11
+0000, Steven D'Aprano wrote: <br>
<blockquote type=cite class=cite cite=""><pre>On Thu, 03 Feb 2011
07:58:55 -0800, Ethan Furman wrote:
> Steven D'Aprano wrote:
[snip]

Yes. Is there a problem? All those paths should be usable from Windows. 
If you find it ugly to see paths with a mix of backslashes and forward 
slashes, call os.path.normpath, or just do a simple string replace:

path = path.replace('/', '\\')

before displaying them to the user. Likewise if you have to pass the 
paths to some application that doesn't understand slashes.


-- 
Steven
</pre><font face="Courier New, Courier"></font></blockquote>Paths that
mix /s and \s are NOT valid on Windows. In one of the setup.py scripts I
wrote I had to write a function to collect the paths of data files for
installation. On Windows it didn't work and it was driving me crazy. It
wasn't until I realized os.path.join was joining the paths with \\
instead of / that I was able to fix it.<br><br>
<tt>def find_package_data(path):</tt><br>
<tt>    """Recursively collect EVERY file
in path to a list."""</tt><br>
<tt>    oldcwd = os.getcwd()</tt><br>
<tt>    os.chdir(path)</tt><br>
<tt>    filelist = []</tt><br>
<tt>    for path, dirs, filenames in
os.walk('.'):</tt><br>
<tt>        for name in
filenames:</tt><br>
<tt>           
filename = ((os.path.join(path, name)).replace('\\', '/'))</tt><br>
<tt>           
filelist.append(filename.replace('./', 'data/'))</tt><br>
<tt>    os.chdir(oldcwd)</tt><br>
<tt>    return filelist</tt> </blockquote><br>
Please check out os.path.normpath() as suggested.  Example:<br>
    >>> import os<br>
    >>> s =
r"/hello\\there//yall\\foo.bar"<br>
    >>> s<br>
    '/hello\\\\there//yall\\\\foo.bar'<br>
    >>> v = os.path.normpath(s)<br>
    >>> v<br>
    '\\hello\\there\\yall\\foo.bar'<br><br>
The idea behind os.path is to cater to the host OS.  Thus
os.path.normpath() will convert to the host's acceptable
delimiters.  That is, you didn't need the .replace(), but rather to
more fully use the existing library to good advantage with
.normpath().<br><br>
However, note that delimiters becomes an issue only when directly
accessing the host OS, such as when preparing command line calls or
accessing native APIs.  Within the Python library/environment, both
'/' and '\' are acceptable.  External use is a different
matter.<br><br>
So, you need to be specific on how and where your paths are to be used.
For instance os.chdir() will work fine with a mixture, but command line
apps or native APIs will probably fail.<br>
</body>
</html>