Python Forum

Full Version: use of sys.argv
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello

what is the use of

if __name__ == "__main__":
  main(sys.argv[1:])
can i pass my file name in this?
when you execute a script from the command like, argv will contain all of the arguments.

example:
$ python myscript.py -a -dc -q
then argv will contain:
argv[0]: myscript.py
argv[1]: -a
argv[2]: -dc
argv[3]: -q
ok. my issue is i don't want to pass argument every time so i define all the arguments in my file called configuration-file.ini and i want it to read from this file, so you tell me how can i do so?

example:
$ python myscript.py configuration-file.ini

here is the whole code: https://github.com/JamesBarwell/haproxy-...-status.py

output: https://github.com/JamesBarwell/haproxy-status.py

i don't wan to pass multiple argument every time when i run the program. so i put all the sock path in a different file and i want to call it from there
Your other thread is all about that - how to use config file, but you don't follow directions. I will lock this thread now. Keep discussion in https://python-forum.io/Thread-hatop-issue