简体   繁体   中英

How to remove backslashes in strings in python

As an output of Pytesseract, I get a string variable which contains backslashes. I would like to remove all of the back slashes.

'13, 0\\\\'70'

Unforturnately the replace function does not work as the string doesn't seem to be an actual string when the variable value is copied. Anybody knows how I can remove all the backslashes?

在此处输入图片说明

I replaced your outermost quotation marks with double-quotes, and then properly applied `replace:

>>> brut_mass = "13, 0\\'70"
>>> brut_mass.replace('\\', '')
"13, 0'70"

Does that solve your problem?

Fixed it with the code below.

brut_mass = repr(brut_mass).replace(" ' ", '')

or alternatively to avoid the double quotations

brut_mass = brut_mass.replace(" ' ", '')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM