Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (45.3k points)

I use python to create my project settings setup, but I need help getting the command line arguments.

I tried this on the terminal:

$python myfile.py var1 var2 var3

In my Python file, I want to use all variables that are input.

1 Answer

0 votes
by (16.8k points)

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']

You can also refer to this blog:

https://docs.python.org/3/tutorial/stdlib.html#command-line-arguments

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...