May 30, 2021 Article blog
Today, the editor introduces you to how to pass variables to the script.
If you want to run a my.py script in python, you only need to run the python my.py on the command line, and the my.py part of this command is called 'argument', and now what you need to do is write a script that accepts the parameters.
from sys import argv
script , first , second , third = argv
print('the script is called ',script)
print('your first variable is ',first)
print('your second variable is ',second) print('your thrid variable is ',thrid)
A call to implement my.py on the command line must pass three parameters
python my.py first 2nd 3nd
You'll see the following effects when the terminal executes:
$ python my.py first 2nd 3nd
the script is called my
your first variable is first
your second variable is 2nd
your thrid variable is 3nd
Recommended good lessons: Python3 Zero Basic Getting Started to Reptile Battle, Python Automation Office and Data Visualization Video Course