When I run python3 myscript.py foo bar 123 then sys.argv holds the value ['myscript.py', 'foo', 'bar', '123']. I'd like to access the name of the command itself (python3 in this case). How can I do that?
1 Answer
Using the psutil module (can be found here), it is possible to retrieve all command line arguments used:
psutil.Process().cmdline()
It returns a list of strings, including the command used to start the python interpreter (e.g. /usr/bin/python3).
python3.7or/usr/bin/pythonsys.version_info?psutiland get thecommandline, find thepythonXprocess running your.py.