程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python method to get command line parameters sys argv

編輯:Python

sys.argv Will run from the command line Python The program is in python or python3 The following parameters have been saved in the form of a list .
for example , Here is test.py The content of the document :

import sys
print(sys.argv)

Command line execution :
python test.py

Output :

['test.py']

Command line execution :
python 'test.py' abc def

Output :

['test.py', 'abc', 'def']

By default, it is separated by spaces , If you want to be a whole , You can put quotation marks on the outside :

Command line execution :
python test.py 'abc def'

Output :

['test.py', 'abc def']

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved