如何在Python中通过选项卡启动所有打印
我有一个脚本(Python),由另一个脚本(JavaScript)调用。为了在命令行中获得更好的日志可读性,我希望下标的所有打印(在 Python 中)都以表格开头。有没有办法用一个命令来做到这一点,或者我应该在所有打印的开头手动放置一个 \t
?
我想在调用脚本中添加选项卡,但是当连续有多个打印时,只有第一个获得选项卡。
PS:如果有帮助的话,Python脚本的调用:
const spawn = require("child_process").spawn;
const pythonProcess = spawn('python3', ["../pythonscript.py"]);
pythonProcess.stdout.on('data', (data) => {
buff = Buffer.from(data.toString().trim(), "utf-8");
console.log('Python answer = ' + buff.toString());
});
I have a script (in Python), that is called by another script (in JavaScript). And to have better readability of the log in my command line, I'd like that all the prints of the subscript (in Python) start with a tabulation. Is there a way to do that with one command, or should I put manually a \t
at the beginning of all my print?
I wanted to add the tab in the calling script, but when there are several prints in a row, only the first one gets the tab.
PS: if it can help, the calling of the Python script:
const spawn = require("child_process").spawn;
const pythonProcess = spawn('python3', ["../pythonscript.py"]);
pythonProcess.stdout.on('data', (data) => {
buff = Buffer.from(data.toString().trim(), "utf-8");
console.log('Python answer = ' + buff.toString());
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这显然是在 Javascript 中完成的后处理步骤。
除非您完全控制脚本,否则有很多方法可以在不使用制表符的情况下打印内容:
\n
自动日志/警告消息的只需使用
JS 中的 buff.toString().split("\n").join("\n\t")
。I think this is clearly a post-processing step to be done in Javascript.
Unless you have complete control over your script, there is lots of ways how things might be printed without tab:
\n
Just use
buff.toString().split("\n").join("\n\t")
in JS.