Issue
What does it mean to call a module with parameters
python mymod.py 50?
What does it mean and what will happen?
Solution
It simply means you pass 50 as string parameter to the python script mymod.py.
Below is a sample code of mymod.py to show what will happen.
import sys
print("Hello World")
print(sys.argv)
if len(sys.argv) > 1:
print(sys.argv[1])
You could copy this code snippet into mymod.py and test in your PC by running
python mymod.py 50
and you may get result like the following:
Hello World
['test.py', '50']
50
As a result, in mymod.py we could get the passed parameter from the built-in sys.argv var.
Hope it helps.
Answered By - Jack Smith Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.