How to get path of a .py script

Skip Montanaro skip at pobox.com
Wed Dec 11 14:42:22 EST 2002


    Manuel> if __name__ == '__main__':
    Manuel>     p = sys.argv[0]
    Manuel> else:
    Manuel>     p = __file__

This test won't be necessary in 2.3.  Consider:

    % cat > f.py
    import sys
    print sys.argv[0]
    print __file__
    % python f.py
    f.py
    f.py

This is with current CVS.  Just an FYI.

-- 
Skip Montanaro - skip at pobox.com
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list