0

I have a config.ini file containing delimiter = \t which i now want to read using the python3 ConfigParser. However, the resulting string is '\\t' instead of '\t' which breaks my program. Is there a more elegant option to solve this problem instead of just manually stripping the extra '\' from every variable containing an escaped character? I cannot find an option for ConfigParser().read() to not escape the backslash it finds in the file.

PDiracDelta
  • 2,048
  • 3
  • 18
  • 37

1 Answers1

1

Python3 has a 'unicode_escape' codec.

r"a\tb".decode('unicode_escape')

'a\tb'

Sources:

https://bytes.com/topic/python/answers/37952-escape-chars-string

how do I .decode('string-escape') in Python3?

Community
  • 1
  • 1
Graffiti Plum
  • 95
  • 1
  • 8
  • Worth noting that `unicode_escape` in Python 3 is for `bytes` only, **not** `str`. You'll have to juggle a bit converting back and forth to use it. – MestreLion Jul 28 '21 at 19:24