简体   繁体   English

命令行中的python脚本,参数应为选项列表

[英]python script from the command line ,the arguments should be a list of options

I would like to run my python script from the command line when supplies with some arguments. 当提供一些参数时,我想从命令行运行python脚本。 However, one of the arguments should be a list of options specific to a segment of the script. 但是,参数之一应该是特定于脚本段的选项列表。 Example: MODULES_TO_INSTALL = ['sale','purchase','account_accountant',] 示例:MODULES_TO_INSTALL = ['sale','purchase','account_accountant',]

how can I do this: python fichier.py liste_modules_to_install 我该怎么做:python fichier.py liste_modules_to_install

I've done something similar in the past. 我过去做过类似的事情。 It might be easier if instead of sending them as a list already, you call your script like so, 如果像这样调用脚本,而不是将它们作为列表发送出去,可能会更容易,

python script.py module1 module2 ... moduleN

Then a simple line of code to read in these passed modules from command line would be, 然后,从命令行读取这些传递的模块的简单代码行将是,

import sys
MODULES_TO_INSTALL = sys.argv[1:]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM