String handling bug in Python

Delaney, Timothy tdelaney at avaya.com
Tue Apr 30 00:37:56 EDT 2002


> From: David Bolen [mailto:db3l at fitlinxx.com]
> "Delaney, Timothy" <tdelaney at avaya.com> writes:
> 
> > import os.path
> > 
> > path = '//computer/path/to/file'
> > path = os.path.normpath(path)
> > print path
> 
> Um, yeah, but why bother?  I suppose if I were going to present it to
> a user but wanted the source to use forward slashes I might do this,
> but it's already a Windows specific reference, so I'd probably just go
> with backslashes in the code or just leave the forward slashes
> unconverted.

1. You may need to deal with user-specified paths (e.g. from a properties
file).

2. Who knows what platform your code may be used on. In particular, someone
may try to use it on the (Classic) Mac OS, which uses colons as path
delimiters (and doubled colons for the parent folder). This of course is
most useful for relative paths, but see (1) as well.

While checking this, I noted a bug in the windows version of the docs - in
the "Index" tab, selecting "os.path (standard module)" then selecting
"os.path (standard module)" in the dialog takes you to the macpath module. I
don't know who should be informed of this ...

Tim Delaney





More information about the Python-list mailing list