471,091 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,091 software developers and data experts.

Getting module location

Is it possible for an imported module to find its own location?
--
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.

Jan 5 '06 #1
2 1040
2006/1/5, Thomas Dybdahl Ahle <th****@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.

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit
Jan 5 '06 #2
Den Thu, 05 Jan 2006 14:53:40 +0800. skrev limodou:
2006/1/5, Thomas Dybdahl Ahle <th****@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.

Jan 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Oliver Spiesshofer | last post: by
reply views Thread by Josiah Carlson | last post: by
reply views Thread by Steven Bethard | last post: by
32 posts views Thread by Matias Jansson | last post: by
2 posts views Thread by dmitrey | last post: by
40 posts views Thread by rjcarr | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.