[英]Trying to open and read a file in python but it creates and opens an empty file
[英]with open in Python creates an empty file
這件事讓我發瘋...
我使用Python來編寫文件。 出於測試目的,我將其限制為最小:
with open(save_dir + filename + '.txt', 'w+') as out_file:
out_file.write('HI\n')
這是非常簡單的事情。 但是文件創建到了正確的目錄,但是沒有寫入任何內容。
我正在尋求幫助以嘗試調試代碼。 因為它很簡單。 我被卡住了。 這里的錯誤可能是什么? 有任何想法嗎?
如果要使用filename變量,則必須導入sys。
from sys import argv
script,input_file,output_file = argv
content = open(input_file,"r").read()
t = open(output_file,"w")
t.write(content)
t.close()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.