More elegant way to cwd?

Steve Holden steve at holdenweb.com
Tue Dec 28 07:49:26 EST 2004


Kamilche wrote:

>> Other than using os.pardir instead of '..', and possibly adding
>> an "os.path.abspath()" call to the last bit (or does realpath
>> already do that?  It's unclear from the docs), I can't see
>> anything fundamental I'd do differently... except package these
>> functions up as nice clean subroutines, possibly in a library
>> package, that I could then use in code that would magically
>> become "elegant" (IMHO) by avoiding the repetition of all
>> that non-elegant stuff above...
>>
>> -Peter
> 
> 
> Well... but to call it from the shared directory, I'd have to first 
> switch to the shared directory! Which would defeat the purpose.
> 
> I wish there was a way to store this in a single file and call it from 
> any script, but I'm unwilling to keep all my scripts in one folder to 
> accomodate it. If only Python would let you import modules from 
> different directories. :-/
> 
> --Kamilche

Maybe I'm misunderstanding your requirements, but it seems to me 
perfectly practical to keep that script in a standard place (say, 
lib/site-packages, which was intended for exactly that purpose) and 
import it from there. There's no reason why its location has to relate 
to the location of the scripts that import it and use that function from it.

What am I missing?

regards
  Steve
-- 
Steve Holden               http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC      +1 703 861 4237  +1 800 494 3119



More information about the Python-list mailing list