Name of the Script

Paul Moore paul.moore at uk.origin-it.com
Mon Mar 5 08:48:28 EST 2001


On Mon, 5 Mar 2001 03:21:29 +0100 , "Alex Shindich"
<alex at shindich.com> wrote:

>try the following:
>
>import sys
>print sys.argv[0]
>....
>The first argument in the argument list is the name of the script that got
>invoked.

This doesn't always include full pathname information. On Windows,

--- a.py ---
import sys
print sys.argv[0]
---

python a.py

just prints "a.py". Is there a way of getting the *full* script name.
For example, so that the script can locate a data file which is held
in the same directory as the script itself.

(sys.argv[0] is probably fine in 99.9% of cases, but there are subtle
borderline cases which I can imagine could cause problems).

Paul.




More information about the Python-list mailing list