Frage

I have been trying the following, as suggested by many post, but I am still getting

ValueError: invalid literal for int() with base 10: 'gap_interval.py'. What am I missing?

import sys 

if __name__ == '__main__':
    n = 4
    a = []
    for i in sys.argv:
        print int(i.strip())
War es hilfreich?

Lösung 2

You need to skip sys.argv[0], which is the script's name:

for i in sys.argv[1:]:
    # ...

Andere Tipps

Python sys.argv always contains the filename as the first argument:

>>> python test.py 1 2 3
>>> sys.argv
['test.py', '1', '2', '3']

If you want to convert it to int, you can do:

nums = map(int, sys.argv[1:])

>>> nums
[1,2,3]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top