Pythonic Idiom For Searching An Include Path

Chris Rebert clp2 at rebertia.com
Wed Jun 23 21:46:11 EDT 2010


On Wed, Jun 23, 2010 at 3:27 PM, Tim Daneliuk <tundra at tundraware.com> 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.

Cook your own. Also, I certainly wouldn't call something this complex
a mere idiom.
You will find optparse, os.sep, and os.walk helpful in writing your code.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list