[英]Python - Comparing console output with a .txt
I wrote a simple python application to print to console:我写了一个简单的 python 应用程序打印到控制台:
print("Hello!")
print("How's it going?")
I than created a text file called 'file.txt' with the following content:然后,我创建了一个名为“file.txt”的文本文件,其内容如下:
Hello!
How's it going?
Is there a way to check if code's output to the console is the same as content in 'file.txt'?有没有办法检查代码的 output 到控制台是否与'file.txt'中的内容相同?
(using windows) (使用窗户)
You can probably use the diff
command.您可能可以使用diff
命令。
diff a.txt <(python a.py)
Output: Output:
2c2
< How's it going?
\ No newline at end of file
---
> How's it going?
Note: This works in bash, ksh, and zsh.注意:这适用于 bash、ksh 和 zsh。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.