James Maguire
James Maguire

Reputation: 570

Trouble with unicode

I have a sqlite database with a list of file locations.

file
"D:\Accounts\Silo\161130_paid\BRW0080929A5C36_001952.pdf"
...

I am trying to get python to rename all the files in this column.

My issue is that when I try to use the string python is seeing the "\161" part as a character and converting it into a "q".

I realise that it is possible to escape this with a backslash, however I have no idea how to do that on a large number of strings.

Upvotes: 0

Views: 38

Answers (1)

brianpck
brianpck

Reputation: 8254

You should use a raw string, by prefixing the r flag.

>>> '\161'
'q'
>>> r'\161'
'\\161'

See string literals from the documentation for more information.

Upvotes: 2

Related Questions