私はプログラムからテキストファイルにリモートで書き込むことができるPythonでプログラムを書いています。関連するコード:非 ".txt"ファイルへの書き込みPython
namein = input("What do you want the filename to be? Don't include an extension...\n")
extin = input("What would you like the extension to be? This program supports:\nMicrosoft Word Document: '.docx'\nPlain Text File: '.txt'\nRich Text File: '.rtf'\nPages Document: '.pages'\n")
aw = input("Do you want to append your text file, or rewrite the whole thing? (append/write) ")
if aw == 'append':
textin = input("In the line below, write the text you want to put into your text document!\n\n")
outfile = open(namein + extin, 'a')
outfile.write(textin)
outfile.flush()
print("Great! Now your text file has been updated!")
print("Your text file:\n")
outfile.close()
outfile = open(namein + extin, 'r')
print(outfile.read())
誰かが「.txt」以外のファイルを選択すると、ファイルを開くことができません。それだけでエラーが発生し、ファイルを開くことができません。これを回避する方法はありますか?
あなたは、サーバーのファイルシステムの任意の場所に任意のファイルを作成させますか? – sdolan
はい、正しい出力形式でファイルにデータを書き込む必要があります。 –
@sdolan: "遠隔的に" :)私は好きです。 –