Question

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())
Was it helpful?

Solution 2

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

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

OTHER TIPS

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]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top