error in path to connection to bank [duplicate]

0

I'm trying to add this path to the connection to the database, 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.

    
asked by anonymous 06.09.2018 / 03:05

1 answer

2

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

Or you escape the backslashes

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

Or use the r prefix:

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

See:

06.09.2018 / 03:08