Syntax error defining def _ _ repr__ (self): in python2.7 class class

I just started to learn python2.7, compared to the examples in the book, but when I write here, I always report grammatical errors.
looked at it, and searched the Internet, but didn"t find out where the mistake was.

this is the source code:

class User(db.Model):
    __tablename__ = "users"
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), unique=True, index=True)
    role_id = db.Column(db.Integer, db.ForeignKey("roles.id")

    def __repr__(self):
        return "<User %r>" % self.username

this is the compilation error:

  File "hello.py", line 44
    def __repr__(self):
      ^
SyntaxError: invalid syntax

Mar.03,2021

role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))

lack of parentheses


User:%r less colons

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36332-2bfea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36332-2bfea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?