0

code here

def button_clicked(self):
    self.lineedit.setText(
        open('test2.txt', 'r', encoding='uft_8')
        data = f.read()
        f.close()
        print(data))

error message SyntaxError: invalid syntax

Expected error resolution

2

1 Answer 1

3

Your are opening the file in the wrong place, try this:

def button_clicked(self):
    f = open('test2.txt', 'r', encoding='uft_8')
    data = f.read()
    f.close()
    self.lineedit.setText(data)

also there is a better way to open read data from a file

def button_clicked(self):
    with open('test2.txt', 'r', encoding='uft_8') as f
        data = f.read()
        self.lineedit.setText(data)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.