G
G
Guerro692020-05-23 00:15:40
Python
Guerro69, 2020-05-23 00:15:40

Is the created file being deleted?

I wrote a simple code that, on clicking a button, creates a notebook with the result, here is the code.

def save_result():
  with open("result.txt", "a") as f:
    z = ui.label_6.text()
    pm = ui.label_8.text()
    time = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
    f.write(f"====================\n\nРезультат работы!\n/z -{z}\n/pm -{pm}\nВремя сохранения: {time}\n\n====================")
  with open("result.txt", "r") as fl:
            print(fl.read())

ui.pushButton_2.clicked.connect(save_result)


The fact is that when I add information to the file, the file itself is nowhere to be found, but it is displayed in the console perfectly, and even after restarting the code, everything that was written in the notepad is there, why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-05-23
@Guerro69

A typo in the code:
print(f.read())
but you need:
print(f1.read())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question