mirror of
https://github.com/ChenKaiLiuG/find_your_own_fxxking_problem.git
synced 2026-06-17 16:54:24 +00:00
Move print.py to directory /run
This commit is contained in:
20
run/print.py
Normal file
20
run/print.py
Normal file
@@ -0,0 +1,20 @@
|
||||
##test
|
||||
import os
|
||||
|
||||
def read_and_print_file(filename):
|
||||
"""讀取並輸出檔案內容"""
|
||||
try:
|
||||
with open(filename, 'r', encoding='utf-8') as file:
|
||||
for line in file:
|
||||
print(line, end='') # end='' 避免多餘的換行
|
||||
except FileNotFoundError:
|
||||
print(f"找不到檔案:{filename}")
|
||||
except Exception as e:
|
||||
print(f"讀取檔案時發生錯誤:{e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
filename = "找找自己問題.txt"
|
||||
if os.path.exists(filename): #檢查檔案是否存在。
|
||||
read_and_print_file(filename)
|
||||
else:
|
||||
print(f"檔案 {filename} 不存在於當前目錄。")
|
||||
Reference in New Issue
Block a user