G
G
Guerro692020-05-21 11:10:16
Python
Guerro69, 2020-05-21 11:10:16

The result is not written to notepad?

I have a Qt5 application and there is a "save" button, here is the function code for it:

def save_result():
    open('result.txt', 'w').write("save test")
    open('result.txt', 'w').close()
    print('test')

ui.pushButton_2.clicked.connect(save_result)  # Сохранить результат

The thing is, when I click on this button, test is displayed in the console, as intended, but nothing is entered in the notepad.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-05-21
@hottabxp

file = open('result.txt', 'w')
file.write("save test")
file.close()

or
with open('result.txt','w') as file:
  file.writelines('save test')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question