Pythonic Idiom For Searching An Include Path
Nobody
nobody at nowhere.com
Thu Jun 24 03:34:22 EDT 2010
On Wed, 23 Jun 2010 17:27:16 -0500, Tim Daneliuk wrote:
> Given a program 'foo' that takes a command line argument '-I
> includefile', I want to be able to look for 'includefile' in a path
> specified in an environment variable, 'FOOPATH'.
>
> I'd like a semantic that says:
>
> "If 'includefile' contains one or more path separator characters,
> ignore 'FOOPATH'. If it contains no path separators, look for it in
> the paths specified by 'FOOPATH', beginning with the leftmost path
> first."
>
> Is there a standard Pythonic idiom for doing this or do I need to cook
> up my own.
There isn't an idiom.
There are a surprising number of choices for such a simple task, e.g.
whether the search path is used for relative paths containing a separator,
whether you stop at the first file which exists or the first file which
meets other criteria (e.g. suitable permissions), whether default
locations come first or last, what happens if a default location is
included in the search path, etc.
More information about the Python-list
mailing list