[Tutor] arg exceptions for scrips

kevin parks kp87@lycos.com
Sat, 14 Jul 2001 00:26:11 +0900


Oh, dopey me! I looked right past that thinking anticipating what that problem was. So what i really want is:

if len(sys.argv) != 3:

and not:

if len(sys.argv) != 2:

Thank you!


On Fri, 13 Jul 2001 11:01:26  
 George Gates wrote:
>
>>if __name__ == '__main__':
>>         if len(sys.argv) < 2:
>>                 print "Usage:", sys.argv[0], "infile outfile"
>>                 sys.exit(1)
>>         else:
>>                 cp(sys.argv[1],sys.argv[2])
>
>The problem is the test of the length should be less than 3, not less than 
>2.  If you executed with only one argument the length of sys.argv would be 
>2, sys.argv[0] for the script name, sys.argv[1] for the argument:
>
>ggates@ggates ggates]$ more arg_count.py
>
>#!/usr/bin/env python
>import sys
>print "The number of arguments are %s: %s" % (len(sys.argv),sys.argv)
>
>[ggates@ggates ggates]$ ./arg_count.py file1
>
>The number of arguments are 2: ['./arg_count.py', 'file1']
>
>[ggates@ggates ggates]$



Get 250 color business cards for FREE!
http://businesscards.lycos.com/vp/fastpath/