0

I have this code :

toto = 'récépissé.pdf'.encode('utf-8')

print(toto)
=> b'r\xc3\xa9c\xc3\xa9piss\xc3\xa9.pdf'

Of course it return a byte type, but I still want a string with the content of the encoded result. I want a string like this :

'r\xc3\xa9c\xc3\xa9piss\xc3\xa9.pdf'

If I try to return a string by using a str() or decode(), it revert back to initial value.

PS: the final purpose is to pass string data in header for dropbox api.

NiBo
  • 1
  • 1
    Your desired result is `'récépissé.pdf'`. Are you sure this is what you want? – gog Aug 24 '22 at 15:20

1 Answers1

0

Probably this is what you are looking for:

toto = 'récépissé.pdf'.encode('utf-8')

print(str(toto).split("'")[1])
WhoKnowsMe
  • 498
  • 2
  • 13
  • I still got extra \ in the variable but not in the print output, so it's seems ok for print but not for use. ` >>> tutu = str(toto).split("'")[1] >>> tutu 'r\\xc3\\xa9c\\xc3\\xa9piss\\xc3\\xa9.pdf' >>> print(tutu) r\xc3\xa9c\xc3\xa9piss\xc3\xa9.pdf ` – NiBo Aug 24 '22 at 15:34
  • @NiBo What do you mean? That returns exactly what you are looking for – WhoKnowsMe Aug 24 '22 at 15:37
  • the print is really good but the variable is not ok – NiBo Aug 24 '22 at 15:41
  • [How to get rid of double backslash in python windows file path string?](https://stackoverflow.com/a/11924842/19392194) – WhoKnowsMe Aug 24 '22 at 15:44