[Tutor] reference to directory a module is located at

Dave Angel davea at ieee.org
Thu Jun 18 18:48:40 CEST 2009

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,

But the OP wanted the directory, which can be extracted with method dirname:

import os
print __file__
print os.path.dirname(__file__)

More information about the Tutor mailing list