Python:添加到txt文件

时间:2015-11-30 16:39:14

标签: python

这是我的代码(抱歉使用其他语言):

def answer_L():
    while True:
        question = input("\tFikseerige sade kujul [Identifikaator] [20] (C): ")
        if question == "C": #Läheb algusesse tagasi
            main()
        try:
            nimi = re.search(r"\[([A-Za-z]+)\]", question)
            number = re.search(r"\[([0-9]+)\]", question)
            number = number.group(0)
            nimi = nimi.group(0)
        except Exception:
            continue
        if ((nimi[0] and nimi[-1] and number[0] and number[-1]) != ("[" or "]")):
            sademed = nimi + number
            to_txt = str(sademed)
        with open('andmebaas.txt', 'a') as file:
            file.write(datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S'))
            file.write(" - " + to_txt + "\n")
            print("\tSade fikseeritud!")
            print("")
            main()

它曾经工作,向txt添加了输入,但现在它突然决定不向txt文件添加任何内容。谁能告诉我这里有什么问题?

0 个答案:

没有答案