直接通过命令行linux执行python

2024-09-27 22:34:39 发布

您现在位置:Python中文网/ 问答频道 /正文

如何运行简单的python脚本并将其保存在文件中,但直接保存在linux命令行中:

fox@fox:/opt/gera# python -c print "aaaaa" > myfileName

但它只是不打印任何东西而不是“aaaaa”。你知道吗


Tags: 文件命令行脚本linuxprintoptaaaaafox
3条回答
python -c 'print "aaaaa"' > myfileName

在您的示例中,python运行python -c print,并给出“aaaaa”作为参数。你知道吗

你必须引用整个命令:

python -c 'print "aaaaa"' > myfileName

否则,您将在Python中执行print(在Python 2中打印换行符,在Python 3中什么都不做,因为您只需计算函数print,而不调用它),并将aaaaa作为参数传递给脚本。你知道吗

你需要在代码周围加引号。你知道吗

python -c 'print "aaaaa"' > myfileName

相关问题 更多 >

    热门问题