path.startswith(dir)?

Magnus Lie Hetland mlh at vier.idi.ntnu.no
Fri May 10 15:34:31 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?

And -- ensuring that dir ends with a separator can be done with

  dir = join(dir, '')

This ought to be a safe/platform independent way of doing it, right?

--
Magnus Lie Hetland                                  The Anygui Project
http://hetland.org                                  http://anygui.org



More information about the Python-list mailing list