Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
use of sys.argv
#1
hello

what is the use of

if __name__ == "__main__":
  main(sys.argv[1:])
can i pass my file name in this?
#2
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
#3
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
#4
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs



Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 801 May-02-2023, 08:40 AM
Last Post: Gribouillis
  sys.argv method nngokturk 3 1,093 Jan-23-2023, 10:41 PM
Last Post: deanhystad
  import argv Scott 3 5,925 Apr-01-2021, 11:03 AM
Last Post: radix018
  Not all data returned from sys.argv ecdhyne 2 2,776 Sep-05-2019, 08:27 PM
Last Post: buran
  Pyinstaller with Sys.Argv[] - “Failed to Execute Script”? ironfelix717 0 5,323 Aug-07-2019, 02:29 PM
Last Post: ironfelix717
  I see is that sys.argv contains character strings helenharry 2 2,765 Jan-09-2019, 11:34 AM
Last Post: DeaD_EyE
  How argv works? Philia 7 4,848 Dec-26-2018, 12:20 AM
Last Post: metulburr
  sys.argv correct sintax? enricosx 3 3,229 Jul-25-2018, 09:27 AM
Last Post: buran
  I gotta problem with making argv parameters Bozx 3 4,070 Apr-04-2017, 03:44 AM
Last Post: alicarlos13
  argv IndexError hsunteik 2 4,549 Dec-19-2016, 06:19 AM
Last Post: hsunteik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020