error in the path to bank connection

Asked

Viewed 136 times

0

I’m trying to add this path to the connection to the bank, and it gives me this error:

File "C:/Users/gabri/PycharmProjects/allbd_s/conc.py", line 4
    path='C:\Usuario\gabri\SQLite\conx'
        ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Process finished with exit code 1*

The algorithm is this:

import sqlite3

#caminho
path = 'C:\Usuario\gabri\SQLite\conx'

#criar bd
conn = sqlite3.connect(path+r'teste.db')

PS: the path address is correct.

1 answer

2


The path seems to be correct, but it is not. The backslash is the escape sequence within a string, then \U are not two characters, but only one.

Or you escape the inverted bars

path = 'C:\\Usuario\\gabri\\SQLite\\conx'

Or use the prefix r:

path = r'C:\Usuario\gabri\SQLite\conx'

Behold:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.