【问题标题】:Printing .py file output in command line在命令行中打印 .py 文件输出
【发布时间】:2020-06-04 13:57:43
【问题描述】:
我正在尝试从命令行访问 python 函数,并且我想编写这样一个命令来在终端中打印输出。以下不起作用。我能改变什么?
python -c 'from laser import Laser; laser = Laser();l = laser.embed_sentences("hello", lang = "en").shape == (1, 1024); print(l)'
【问题讨论】:
标签:
python
command-line
terminal
【解决方案1】:
(base) ~ % python -c 'print("hello, world")'
hello, world
当我通过python -c 运行 python 时,打印效果很好。您确定您的终端没有通过省略最后一行(在这种情况下,仅此行)来截断您的输出吗?您可以尝试创建一个单行文件(末尾没有换行符)然后运行cat [filename](这就是我有时会发现我的终端正在执行此操作的方式)
【解决方案2】:
-c cmd : program passed in as string (terminates option list)
这是要使用的正确标志。这一定是 CLI 配置问题。或者脚本运行的时间比您预期的要长,并且似乎没有生成输出。
python -c 'print("hello")' 有效吗?