Flag control variable

Gary Herron gary.herron at islandtraining.com
Tue Feb 11 14:20:27 EST 2014


On 02/11/2014 11:01 AM, luke.geelen at gmail.com wrote:
> when using python script.py 2 \* 2 i get Traceback (most recent call 
> last): File "math2.py", line 5, in <module> sign = int(sys.argv[2]) 
> ValueError: invalid literal for int() with base 10: '*' 

Stop trying to guess what is going on.  Print out sys.argv, and *see* 
what values are there.  Then read the error message.

You wrote your script expecting sys.argv[2] to contain an int, but in 
fact (according to the error) it contains a '*' -- which can't be 
converted to an integer obviously.  Your error is in running the script 
incorrectly, *OR* in your understanding of how the command line 
arguments get placed in sys.argv.  In either case you best bet is to 
examine sys.argv by printing it (or examining it within a debugger) and 
*see* what values it contains.  Then adjust your script (or the running 
of it) accordingly.

These are very beginner level debugging suggestions.  If you develop the 
skill to read and understand the error messages, and the skill to print 
(or otherwise examine) the values your program is dealing with, you 
progress will by 100's of times faster then this slow wait for someone 
to respond to on this list.

Gary Herron



More information about the Python-list mailing list