0
私は多少Pythonに慣れていて、テキストファイルに書き込もうとしています。ただし、次のコードでは変数をテキストファイルに書き込まず、空のテキストファイルを作成するだけです。なぜこれが分かっていますか?なぜこのファイルへの書き込みが機能しないのですか?
crop = input("Which crop? ")
quantity = input("How many? ")
def appendA():
file.write (quantity + ' ')
def appendB():
file.write ('\n')
file.write (crop + ' ')
file.write (quantity + ' ')
file = open ('cropdatabase.txt', 'a+')
if crop in file:
appendA()
else:
appendB()
Pythonのバージョンを指定します。 –
Pythonのバージョンは3.5.1です – superato
完了したらファイルを閉じていますか? 'file.close()' – mattvivier