Strange side effect from reading a list of numbers from argv

Harold Gottschalk heg at softbrew.com
Sun Jul 18 17:55:58 EDT 1999


I just wrote this program to become familiar with python and I do not
understand why it works with a list I create with in the program and not
when I use sys.argv[1:].

I am sure there is some nuance I am missing, but an explanation to its
behavior would be helpful.

If you switch the comment between the two for statements you will see the
different results.  Code follows below.

When using the command line to get your list:
findCurrent1.py 3 4 5 90 33 59604 1
largeNum =  90  smallNum =  999999999

When using the internal list the results are:
largeNum =  59604  smallNum =  1

Thanks for the help,

Harold


_____Code______

import sys

#Intialize Varables
largeNum = -999999999
smallNum = 999999999
list = [3,4,5, 90, 33, 59604, 1]

for value in sys.argv[1:]:
#for value in list:
    if value >= largeNum:
        largeNum = value
    if value <= smallNum:
     smallNum = value

print "largeNum = ",largeNum," smallNum = ",smallNum

_______END CODE_______






More information about the Python-list mailing list