from sys import argv - what is the function of “script”

后端 未结 4 1740
悲哀的现实
悲哀的现实 2020-12-30 04:35

I am reading \"Learn Python the Hard Way\" and was confused by the \"script\" part of the second line.

from sys import argv
script, filename = argv
         


        
4条回答
  •  半阙折子戏
    2020-12-30 05:28

    The first item in argv is the name of the Python script you're running. Any additional arguments (the filename, in this case) are arguments passed to this script.

    These two arguments are assigned the names script and filename. It's entirely possible that script is never used again; it's basically a placeholder. If you remove it, however, you'd do filename = argv[1] instead.

提交回复
热议问题