snippetpythonCritical
How do I access command line arguments?
Viewed 0 times
accesshowlinecommandarguments
Problem
I use python to create my project settings setup, but I need help getting the command line arguments.
I tried this on the terminal:
In my Python file, I want to use all variables that are input.
I tried this on the terminal:
$python myfile.py var1 var2 var3In my Python file, I want to use all variables that are input.
Solution
Python tutorial explains it:
More specifically, if you run
import sys
print(sys.argv)More specifically, if you run
python example.py one two three:>>> import sys
>>> print(sys.argv)
['example.py', 'one', 'two', 'three']Code Snippets
import sys
print(sys.argv)>>> import sys
>>> print(sys.argv)
['example.py', 'one', 'two', 'three']Context
Stack Overflow Q#4033723, score: 1021
Revisions (0)
No revisions yet.