Prev: How to send a non-standard IMAP command?
Next: modifying standard library functionality (difflib)
From: Tim Daneliuk on 23 Jun 2010 18:27 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. TIA, -- ---------------------------------------------------------------------------- Tim Daneliuk tundra(a)tundraware.com PGP Key: http://www.tundraware.com/PGP/
From: Chris Rebert on 23 Jun 2010 21:46 On Wed, Jun 23, 2010 at 3:27 PM, Tim Daneliuk <tundra(a)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
From: Nobody on 24 Jun 2010 03:34 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.
From: Gregory Ewing on 24 Jun 2010 03:57 Tim Daneliuk wrote: > "If 'includefile' contains one or more path separator characters, > ignore 'FOOPATH'. Are you sure that's exactly what you want? Usually with such things the distinction is absolute vs. relative, not whether there is more than one pathname component. E.g. in a C file, #include "GL/gl.h" will search the include path for a directory called "GL" containing a file called "gl.h". -- Greg
From: Tim Daneliuk on 24 Jun 2010 08:38 On 6/24/2010 2:57 AM, Gregory Ewing wrote: > Tim Daneliuk wrote: >> "If 'includefile' contains one or more path separator characters, >> ignore 'FOOPATH'. > > Are you sure that's exactly what you want? Usually with > such things the distinction is absolute vs. relative, > not whether there is more than one pathname component. > E.g. in a C file, > > #include "GL/gl.h" > > will search the include path for a directory called > "GL" containing a file called "gl.h". > Point well taken, thanks. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra(a)tundraware.com PGP Key: http://www.tundraware.com/PGP/
|
Next
|
Last
Pages: 1 2 Prev: How to send a non-standard IMAP command? Next: modifying standard library functionality (difflib) |