Strange side effect from reading a list of numbers from argv
Fredrik Lundh
fredrik at pythonware.com
Mon Jul 19 05:59:13 EDT 1999
More information about the Python-list mailing list
Mon Jul 19 05:59:13 EDT 1999
- Previous message (by thread): Signature 0.1 does not work well
- Next message (by thread): Strange side effect from reading a list of numbers from argv
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Harold Gottschalk <heg at softbrew.com> wrote: > 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. adding a "print type(value)" or "print repr(value)" inside the loop helps you figure out what's going on. then read http://www.python.org/doc/current/ref/comparisons.html to find the rules for comparing apples and oranges: "Most other types compare unequal unless they are the same object; the choice whether one object is considered smaller or larger than another one is made arbitrarily but consistently within one execution of a program." adding a "value = int(value)" inside the loop helps you do what you want. if you're feeling fancy, you can also write that as: for value in map(int, sys.argv[1:]): ... </F>
- Previous message (by thread): Signature 0.1 does not work well
- Next message (by thread): Strange side effect from reading a list of numbers from argv
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list