简体   繁体   English

命令行中的 Printing.py 文件 output

[英]Printing .py file output in command line

I am trying to access a python function from the command line, and I would like to write such a command that will print the output in the terminal.我正在尝试从命令行访问 python function,并且我想编写这样一个命令,该命令将在终端中打印 output。 The below doesn't work.以下不起作用。 What could I change?我能改变什么?

python -c 'from laser import Laser; laser = Laser();l = laser.embed_sentences("hello", lang = "en").shape == (1, 1024); print(l)'
(base) ~ % python -c 'print("hello, world")'
hello, world

Printing works fine for me when running python through python -c .通过python -c运行 python 时,打印对我来说效果很好。 Are you sure your terminal isn't truncating your output by omitting the last (and in this case, only) line?您确定您的终端没有通过省略最后一行(在这种情况下,仅此行)来截断您的 output 吗? You could try creating a single line file (no newline at the end) and then running cat [filename] (which is how I sometimes discover that my terminal is doing this)您可以尝试创建一个单行文件(最后没有换行符),然后运行cat [filename] (这就是我有时发现我的终端正在这样做的方式)

-c cmd: program passed in as string (terminates option list)

That is the correct flag to be used.那是要使用的正确标志。 This must be a CLI config issue.这一定是 CLI 配置问题。 Or the script is taking longer than you are expecting to run and it appears no output is generated.或者脚本运行的时间比您预期的要长,并且似乎没有生成 output。

Does python -c 'print("hello")' work? python -c 'print("hello")'工作吗?

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

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