** * This article is from Udemy "[Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style](https://www.udemy.com/course/python-beginner/" Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style ")" It is a class notebook for myself after taking the course of. It is open to the public with permission from the instructor Jun Sakai. ** **
terminal
python3 test.py arg1 arg2
import sys
print(sys.argv)
result
['test.py', 'arg1', 'arg2']
When running a Python file from a terminal, you can pass arguments after the Python file name.
These arguments are stored as a list in sys.argv
. Therefore,
import sys
for i in sys.argv:
print(i)
result
test.py
arg1
arg2
This kind of usage is possible.
Recommended Posts