[Tutor] reference to directory a module is located at

Elisha Rosensweig benshafat at gmail.com
Thu Jun 18 22:29:41 CEST 2009


Thanks - just what I needed (and thanks to all the others too)

Elisha

On Thu, Jun 18, 2009 at 12:48 PM, Dave Angel <davea at ieee.org> wrote:

> bob gailer wrote:
>
>  Elisha Rosensweig wrote:
>>
>>> > Hi,
>>> >
>>> > How can I determine the directory in which a module is located, from >
>>> within that module?
>>>
>>>
>> sys.modules[__name__].__file__
>> -- Bob Gailer
>>
> Or more simply,
>   __file__
>
> But the OP wanted the directory, which can be extracted with method
> dirname:
>
> import os
> print __file__
> print os.path.dirname(__file__)
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090618/c4b9dde5/attachment.htm>


More information about the Tutor mailing list