문제

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())
도움이 되었습니까?

해결책 2

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

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

다른 팁

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]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top