Python Forum
Help with "getopt" module - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Help with "getopt" module (/thread-2772.html)



Help with "getopt" module - fastfusion - Apr-08-2017

I really need help with the getopt module.
I'm trying to follow the "Blackhat Python" book and I am trying to make a Netcat replacement.
In it, I need to parse the command line arguments:
 opts, args = getopt.getopt(sys.argv[1:], #this part I dont understand) 
How do I use that part to my advantage? Please someone help!


RE: Help with "getopt" module - Ofnuts - Apr-08-2017

https://docs.python.org/2/library/getopt.html


RE: Help with "getopt" module - wavic - Apr-08-2017

Sys.argv is a list which holds the all command line arguments.
Because its first element is the script's name the actual arguments start from index 1. [1:] part is called slicing. It means get the list elements from index 1 to the end.


RE: Help with "getopt" module - metulburr - Apr-09-2017

I would use the argparse module instead. It is much better. 
https://ttboj.wordpress.com/2010/02/03/getopt-vs-optparse-vs-argparse/


RE: Help with "getopt" module - snippsat - Apr-09-2017

Or even better Click,i have a run with Click here.