Can Python Module Locate Itself?

Juha Autero Juha.Autero at
Wed Sep 17 08:45:05 CEST 2003

sj <_remove_jones57 at> writes:

> I have written several small shell utilities in Python and typically use 
> comments at the start of the source file as documentation. A command line 
> option allows the user to read this documentation.  The problem is that I 
> have to explicitly code the source files location within the source which 
> is not very portable.  Is there anyway for a python module to locate its 
> own source ?

I don't know about locating source, but does the documentation have to
be in comments? I think documentation strings exist for this purpose.
This is an example file. By using command line argument '-h' user can
print this documentation.
import sys
if sys.argv[1] == "-h":
    print __doc__

Juha Autero
Eschew obscurity!

More information about the Python-list mailing list