path.startswith(dir)?

Daniel Dittmar daniel at dittmar.net
Sat May 11 14:38:16 EDT 2002


 > I've got some code which tests for
 >
 >   commonprefix([dir, filename]) == dir
 >
 > Assuming that dir ends with a separator (e.g. '/'), it ought to be
 > just as safe (and more concise) to use
 >
 >   filename.startswith(dir)
 >
 > no?

On Windows:
 >>> os.path.abspath ('.')
'H:\\Perforce'
 >>> os.path.abspath ('h:\\perforce')
'h:\\perforce'

You'll have to add a os.path.normcase into the mix.

Daniel




More information about the Python-list mailing list