How Get Name Of Working File

Christian Heimes lists at cheimes.de
Sun Mar 22 10:58:05 EDT 2009


Victor Subervi schrieb:
> Hi;
> If I am writing a script that generates HTML, how do I grab the name of the
> actual file in which I am working? For example, let us say I am working in
> test.py. I can have the following code:
> 
> import os
> dir = os.getcwd()
> 
> and that will give me the working dir. But what about "test.py"?

The module variable __file__ contains the file name of the current
Python module.

Christian




More information about the Python-list mailing list