![](/img/trans.png)
[英]trying to get an output from a file using the user input value then print the value in python
[英]testing function in python that need to get input from user and print the output, using pycharm and pytest
我在 python 3 中編寫了代碼,並想使用 Pytest 框架為我的代碼編寫測試。 我有一個函數(主函數)從用戶那里獲取輸入(一個文件名),處理它並將結果打印到屏幕上(答案可以是對的或錯的)。 如何編寫自己輸入數據的測試函數(用於主輸入)並檢查打印到控制台的內容? (我使用 Pycharm)
def main():
file_input = input(str('path to your file here'))
with open(file_input, mode="r") as f:
for line in f:
reader = line.split()
# Convert to boolean <-- Not working?
flag = bool(reader[0])
if flag:
print('flag == True')
else:
print('flag == False')
if __name__ == '__main__':
main()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.