关闭。这个问题需要details or clarity .它目前不接受答案。
想改善这个问题吗?通过 editing this post 添加详细信息并澄清问题.
5年前关闭。
Improve this question
为什么python脚本输出的末尾有一个百分号?
$ echo "测试测试"|修剪
测试一下%
#!/usr/bin/env python
import sys
if __name__ == "__main__":
for line in sys.stdin:
sys.stdout.write(''.join(line.split()))
最佳答案
%
您会看到实际上可能是您的 shell 提示,而不是您的程序输出的一部分。您没有在输出后写一个新行,所以 shell 提示出现在最后一个命令输出的最后。
可能的解决方案:
print
而不是 sys.stdout.write
+ "\n"
在输出末尾添加换行符print()
到您的程序结束 关于python - python脚本输出末尾的百分号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36270945/