Suggestion for os.path.join

David Morgenthaler boogiemorg at aol.com
Fri May 25 02:02:39 EDT 2001


"carlos eberhardt" <carlos.eberhardt at techrepublic.com> wrote in message news:<_bXO6.24$oF3.4052 at news7.onvoy.net>...
> Could os.path.normcase or os.path.normpath solve your problem?
> 
> "David Morgenthaler" <boogiemorg at aol.com> wrote in message
> news:f9b3eae9.0105231418.3bcc1b44 at posting.google.com...
> > We use os.path.join() extensively to keep our code platform
> > independent. But we sometimes have problems on win32 when the
> > resulting path is passed to a C-extension -- not all C-extensions
> > (e.g., gdchart) are smart enough to handle the result.
> 
> <snip>

On Windows os.path.normpath converts everything to '\', and this is the problem. The '\' works
well with anything Pythonic. But when used with C-extensions the '\'
becomes an escape character within the C string, thus ruining the path.

Essentially I want the opposite -- something like normpath that forces the
use of '/'. Python is benevolent enough to handle these paths, and they also
work with C-extensions. Right now I find myself with a two-step incantation:
os.path.join() followed by string.replace(pathString, '\\','/'). This has no
effect when run on Unix platforms, but it doesn't hurt either.

Dave



More information about the Python-list mailing list