path.startswith(dir)?

Sean 'Shaleh' Perry shalehperry at attbi.com
Sat May 11 11:19:40 EDT 2002


On 10-May-2002 Magnus Lie Hetland wrote:
> 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?
> 

Sorry for not noticing the hidden os.path import.

Could you show us say 10 lines or so of this code being used?  From the above
code it looks ok, but may have hidden snags.  Than again, maybe this is simple
and I am not seeing it.





More information about the Python-list mailing list