[Python-3000] Path Reform: Get the ball rolling

Talin talin at acm.org
Wed Nov 1 17:45:41 CET 2006


Michael Urman wrote:
>>        p = os.path.normpath( os.path.join( __file__, "../..", "lib" ) )
> 
> Shouldn't an example avoid using the path separator directly within a
> string literal?
> 
>    p = path.normpath(path.join(__file__, "..", "..", "lib"))

No need. 'normpath' will automatically convert the forward-slash into a 
backward-slash on Win32 platforms.

More generally: My defacto solution to the problem of path manipulation 
is that the "path algebra" operators are strings, rather than object 
methods or functions. When you join two paths, all of the instructions 
as to how to combine the two paths are contained in the string.

-- Talin



More information about the Python-3000 mailing list