是否可以将命令作为参数传递给 Python,而不是将其写入文件中?
例如文件Hello.py
的内容是:
=========================
print"Hello World!"
=========================
当我们这样做时:
$ Python Hello.py
它说:
Hello World!
但是是否可以直接将命令作为 Python 参数给出: 喜欢:
$python <Some Option> "print 'hello World!'"
最佳答案
您可以使用-c
option :
Execute the Python code in command. command can be one or more statements separated by newlines, with significant leading whitespace as in normal module code.
示例:
python -c "print 'Hello World!'"
关于Python - 将命令作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21673992/