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.
            Asked
            
        
        
            Active
            
        
            Viewed 1,655 times
        
    1
            
            
         
    
    
        PDiracDelta
        
- 2,348
- 5
- 21
- 43
1 Answers
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
 
    
    
        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
- 
                    i want to point people to [this topic](https://stackoverflow.com/q/1885181) for more discussion on this. [this answer](https://stackoverflow.com/a/69772725) in particular seems to be the most flexible overall – starwarswii Oct 26 '22 at 21:43