sys.argv[1] meaning in script

后端 未结 9 1482
野趣味
野趣味 2020-11-22 11:02

I\'m currently teaching myself Python and was just wondering (In reference to my example below) in simplified terms what the sys.argv[1] represents. Is it simpl

9条回答
  •  -上瘾入骨i
    2020-11-22 11:43

    Just adding to Frederic's answer, for example if you call your script as follows:

    ./myscript.py foo bar

    sys.argv[0] would be "./myscript.py" sys.argv[1] would be "foo" and sys.argv[2] would be "bar" ... and so forth.

    In your example code, if you call the script as follows ./myscript.py foo , the script's output will be "Hello there foo".

提交回复
热议问题