我如何从参数中获取字符串并在if语句中使用它?

时间:2015-07-03 01:29:36

标签: python string if-statement

我知道如何在bash中执行此操作:

mydev> apm install atom-typescript
Installing atom-typescript to /Users/pitosalas/.atom/packages [BABEL] Note: The code generator has deoptimised the styling of "/Users/pitosalas/.atom/packages/atom-typescript/dist/typescript/compiler/checker.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "/Users/pitosalas/.atom/packages/atom-typescript/dist/typescript/compiler/diagnosticInformationMap.generated.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "/Users/pitosalas/.atom/packages/atom-typescript/dist/typescript/compiler/emitter.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "/Users/pitosalas/.atom/packages/atom-typescript/dist/typescript/compiler/parser.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "/Users/pitosalas/.atom/packages/atom-typescript/dist/typescript/services/services.js" as it exceeds the max of "100KB".
✓
mydev>

我将如何在Python中执行此操作?

2 个答案:

答案 0 :(得分:1)

您想要的是以下内容:

#!/usr/bin/python
import sys.argv

if sys.argv[1] == "stringhere":
    print("Argument is equal to string!")

答案 1 :(得分:0)

看一下以下代码来获得一个基本想法:

import sys
print('Nr of arguments:'+ len(sys.argv))
print('Argument List:'+str(sys.argv))

sys.argv变量包含给定的所有参数,并且可以通过python中正常访问数组的方式访问。

您执行程序的方式与bash-way类似:python my program.py arg1 arg2