簡體   English   中英

Python - 將控制台 output 與 a.txt 進行比較

[英]Python - Comparing console output with a .txt

我寫了一個簡單的 python 應用程序打印到控制台:

print("Hello!")
print("How's it going?")

然后,我創建了一個名為“file.txt”的文本文件,其內容如下:

Hello!
How's it going?

有沒有辦法檢查代碼的 output 到控制台是否與'file.txt'中的內容相同?

(使用窗戶)

您可能可以使用diff命令。

diff a.txt <(python a.py)

Output:

2c2
< How's it going?
\ No newline at end of file
---
> How's it going?

注意:這適用於 bash、ksh 和 zsh。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM