2018年1月9日 星期二

Python: Get the command-line arguments passed to a script

Python: Get the command-line arguments passed to a script

Python Basic: Exercise-76 with Solution

Write a Python program to get the command-line arguments (name of the script, the number of arguments, arguments) passed to a script.
Sample Solution:-
import sys
print("This is the name/path of the script:"),sys.argv[0]
print("Number of arguments:",len(sys.argv))
print("Argument List:",str(sys.argv))


This is the name/path of the script: test.py
('Number of arguments:', 4)
('Argument List:', "['test.py', 'arg1', 'arg2', 'arg3']")

沒有留言:

張貼留言

完整的數位線路7 種編碼(Line Coding)模擬器

 完整的數位線路7 種編碼(Line Coding)模擬器 編碼方式說明 Unipolar RZ (歸零編碼) : 訊號在表示 1 時只佔據半個位元時間,隨後「歸零」。這有助於同步,但消耗雙倍頻寬。 Differential (差分編碼) : 訊號的電位不代表 0 或 1,而是...