管道 Python 脚本以便将其与另一个文本文件进行比较

Piping a Python script in order for it to be compared to another text file

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

python myscript.py |差异 test.txt -

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

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

如果你想从其他管道获取数据,比如

ls | python myscript.py

python myscript.py < data.txt

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