Tech
Infected

Linux, OpenSource, Programming And Hacks

Jul 16, 2017

Passing argument from Command-line in Python

Jul 16, 2017
Sometimes it's required to use arguments passed from cli to use in our program. Its very simple to do so..

we just need to use sys module's argv method.

import sys

print(sys.argv[1])
print(sys.argv[2])








Note that using sys.argv[0] will just give program.py, which is in fact the first argument. 




No comments:

Post a Comment