How to retrieve the filename of a module

Lawrence Oluyede raims at dot.com
Thu Oct 20 12:33:54 EDT 2005


Il 2005-10-20, Lawrence Oluyede <raims at dot.com> ha scritto:
> Il 2005-10-20, mku <martin.kuner at thomson.net> ha scritto:
>> Hi,
>>
>> thereŽs a function inside a module. How can these function retrieve
>> the path+name   of his module ? (The path is most important).
>> That should also work if the module is part of a package.
>
>
> rhymes at voodoo:~ $ cat > test.py
> print __file__
> import os
> print os.path.abspath(__file__)
>
> rhymes at voodoo:~ $ python test.py
> test.py
> /home/rhymes/test.py

Also __name__ for the name of the module

-- 
Lawrence
http://www.oluyede.org/blog



More information about the Python-list mailing list