【问题标题】:Piping a Python script in order for it to be compared to another text file管道 Python 脚本以便将其与另一个文本文件进行比较
【发布时间】:2017-11-26 21:59:20
【问题描述】:

我有一个简单的问题:我有一个 python 脚本,它生成一个字符串列表,我希望它能够通过管道输出这个输出,以便它可以与这种形式的现有文本文件进行比较:

python myscript.py | diff test.txt -

在这种情况下,test.txt 文件只是一个文本文件,其中包含每个换行的单词。我怎么会这样做。

【问题讨论】:

  • sys.stdout.write ?
  • 你试过了吗?

标签: python unix diff piping


【解决方案1】:

print()sys.stdout.write() 显示的所有文本(print() 也使用)将通过管道传输到其他命令。

如果您想从其他管道获取数据,例如

ls | python myscript.py

python myscript.py < data.txt

然后使用input()sys.stdin.read()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 2012-09-25
    相关资源
    最近更新 更多