[Tutor] Cannot understand what this means

ALAN GAULD alan.gauld at btinternet.com
Mon Jul 22 21:05:01 CEST 2013


CCing the list.

Please always use ReplyAll to include the list.

Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/



>________________________________
> From: #PATHANGI JANARDHANAN JATINSHRAVAN# <JATINSHR001 at e.ntu.edu.sg>
>To: Alan Gauld <alan.gauld at btinternet.com> 
>Sent: Monday, 22 July 2013, 17:14
>Subject: RE: [Tutor] Cannot understand what this means
> 
>
>Hi
>I have doubts only on the arguments part. 
>
>OK, But what about them?
Do you understand what command line arguments are?

> def main():
>
>>    # This command-line parsing code is provided.
>>    # Make a list of command line arguments, omitting the [0] element
>>    # which is the script itself.
>>    args = sys.argv[1:]


This fetches the command line arguments missing the first which is the program name.
Do you understand slicing? Do you understand how sys.argv works - its similar to
the argc, argv mechanism of  C++ which you've maybe seen before.

>>    if not args:

>>      print 'usage: [--summaryfile] file [file ...]'
>>      sys.exit(1)

The logic here says that if args is empty then print the message and exit

>>    # Notice the summary flag and remove it from args if it is present.
>>    summary = False
>>    if args[0] == '--summaryfile':
>>      summary = True
>>      del args[0]

I have no idea why this is here but for whatever reason he is setting 
the summary flag to True if the first argument was --summaryfile

Now, is there anything else you don't understand? 
The more specific you make your questions the better we can 
answer them. 
Alan G.


More information about the Tutor mailing list