How to retrieve the filename of a module

2005-10-20 Thread mku
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.

Thanks in advance

Martin

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to retrieve the filename of a module

2005-10-20 Thread Lawrence Oluyede
Il 2005-10-20, mku [EMAIL PROTECTED] 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.


[EMAIL PROTECTED]:~ $ cat  test.py
print __file__
import os
print os.path.abspath(__file__)

[EMAIL PROTECTED]:~ $ python test.py
test.py
/home/rhymes/test.py

Bye



-- 
Lawrence
http://www.oluyede.org/blog
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to retrieve the filename of a module

2005-10-20 Thread Jim O'D
mku wrote:
 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.
 
 Thanks in advance
 
 Martin
 

Try the following in the function:

import traceback
f = traceback.extract_stack(limit=2)

If you output f to the interpreter, you'll see the filename but I don't 
know what position in the output list it is guaranteed to be.

Jim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to retrieve the filename of a module

2005-10-20 Thread Lawrence Oluyede
Il 2005-10-20, Lawrence Oluyede [EMAIL PROTECTED] ha scritto:
 Il 2005-10-20, mku [EMAIL PROTECTED] 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.


 [EMAIL PROTECTED]:~ $ cat  test.py
 print __file__
 import os
 print os.path.abspath(__file__)

 [EMAIL PROTECTED]:~ $ python test.py
 test.py
 /home/rhymes/test.py

Also __name__ for the name of the module

-- 
Lawrence
http://www.oluyede.org/blog
-- 
http://mail.python.org/mailman/listinfo/python-list