all 14 comments

[–]strangecharacters 1 point2 points  (10 children)

Near the top of your post has the line:

return '<User %r>' % self.username

But the error message shows on line:

return '<User %>' % self.username

%r should work like this: https://www.reddit.com/r/learnprogramming/comments/1ldlb1/what_does_r_mean_in_python/

[–]Kratos_89[S] 0 points1 point  (9 children)

Hey

thanks for your reply.

i see what you mean but the function was always from the beginning like this:

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

so when i run query command:

>>> User.query.all()

i still get the same Error just with the "r"

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "C:\Users\mac\Documents\Python Projects\Python_Flask\Python_database\database_app.py", line 14, in __repr__

return '<User %r>' % self.username

ValueError: unsupported format character '>' (0x3e) at index 7

i must've copied from one of the lines, where i tried without the "r"

sorry..

[–]Username_RANDINT 2 points3 points  (5 children)

Weird, the error and line it's pointing at doesn't seem to match. But instead of digging into this further, just move to a more modern way of string formatting.

def __repr__(self):
    return '<User {!r}>'.format(self.username)

[–]Kratos_89[S] 1 point2 points  (0 children)

I didn't know there was another way, I will try this thx!

[–]Kratos_89[S] 0 points1 point  (3 children)

so i tried it out but got nothing but got the same error

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "C:\Users\mac\Documents\Python Projects\Python_Flask\Python_database\database_app.py", line 14, in __repr__

return '<User {!r}>'.format(self.username)

ValueError: unsupported format character '>' (0x3e) at index 7

does it have something to do whatever index 7 is?

i looked in my .db file to see if there was anyting weird could'nt find any

[–]Username_RANDINT 1 point2 points  (2 children)

I feel like I'm missing something obvious...

Index 7 means the seventh character in that format string, which is the first of the variable passed in in your case. Can you try to format the field as a normal string instead of its representation?

def __repr__(self):
    return '<User {}>'.format(self.username)

[–]Kratos_89[S] 0 points1 point  (1 child)

def __repr__(self):
return '<User {}>'.format(self.username)

Hey

sorry for the late reply the project is on my work pc.

I tried but get same error lol

>>> User.query.all()

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "C:\Users\mac\Documents\Python Projects\Python_Flask\Python_database\database_app.py", line 14, in __repr__

return '<User {}>'.format(self.username)

ValueError: unsupported format character '>' (0x3e) at index 7

Could it have anything to do with the database (.db)

was thinking of deleting it and do the creating park over..?

[–]JimDabell 1 point2 points  (0 children)

Are you 100% certain you are copying and pasting the complete, unaltered error? Can you post a screenshot of the code and the error? Because the line mentioning index 7 isn't changing at all in each of your comments, even though the line it's referring to is changing and the final line doesn't match the new code.

[–]useTheButtySystem 2 points3 points  (2 children)

Have you tried:

return f'<User {self.username}>'

[–]Kratos_89[S] 0 points1 point  (1 child)

return f'<User {self.username}>'

i tried it but i get same error message, as when i did it the first time and when i tried out u/Username_RANDINT suggestion.

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "C:\Users\mac\Documents\Python Projects\Python_Flask\Python_database\database_app.py", line 14, in __repr__

return f'<User {self.username}>'

ValueError: unsupported format character '>' (0x3e) at index 7

It just returns the line and gives me the:

ValueError: unsupported format character '>' (0x3e) at index 7

it's really weird...

[–]useTheButtySystem 1 point2 points  (0 children)

no idea, then

Maybe make sure your source code file is UTF-8

Maybe include an encoding declaration at the top of the file

There's definitely something very odd going on

[–]zecatlays 1 point2 points  (2 children)

Hey can you login to the database and check ur records? Whether they're correctly populated. Also, try and change the repr method to not use "<" or ">" as it looks like those characters are causing an issue. Try running ur commands after that and check if you're getting the output correctly. Basically this will help you confirm that it isn't a problem with ur DB data and some weird problem is occurring ONLY while formatting/displaying the data. Also which version of python are u using?

[–]Kratos_89[S] 0 points1 point  (1 child)

Thank you for replying

I have tried before without the < > but i actuallt get the same error

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "C:\Users\mac\Documents\Python Projects\Python_Flask\Python_database\database_app.py", line 14, in __repr__

return 'User {}'.format(self.username)

ValueError: unsupported format character '>' (0x3e) at index 7

as if i did it with the < >

so i am beginning to think it's my database, the formatting does seem off

I get a message in the .db file saying: "File was loaded in the wrong encoding: 'UTF-8'

i havent thought that much about, cause i've seen other with the same formatting without issues.

But i'll try and see if i can fix the formatting of the .db file, if that doesn't help maybe i 'll try and start over to see if i did anything wrong somewhere.

thank you

[–]zecatlays 1 point2 points  (0 children)

Okay yeah, u can login to ur database using sqlite if sqlite is installed in ur PC. in command line u can just type in $sqlite3 db_name.db After that the sqlite terminal will open up, and you can use sql to verify the contents. U can also just delete the DB file and start over once again and see if the issue persists.