Getting module location
Thomas Dybdahl Ahle
thomas at localhost.localdomain
Thu Jan 5 08:04:49 EST 2006
Den Thu, 05 Jan 2006 14:53:40 +0800. skrev limodou:
> 2006/1/5, Thomas Dybdahl Ahle <thomas at localhost.localdomain>:
>> Is it possible for an imported module to find its own location?
>
> you can access __file__(missing for built-in modules) or __path__(used
> for a package) attribute to find a module's location.
Super, what I needed seems to be os.chdir(os.path.dirname(__file__)).
Works flawlessly. Thank you.
--
Programmers should realize their critical importance and responsibility in a
world gone digital. They are in many ways similar to the priests and monks of
Europe's Dark Ages; they are the only ones with the training and insight
to read and interpret the "scripture" of this age.
More information about the Python-list
mailing list