0

I am new to Python.

I have the following config file

test.conf

path=Dtest.appender\=console

Following is the python code in which I read a config from .conf file using ConfigParser

from ConfigParser import SafeConfigParser

def func(config=SafeConfigParser):
    with open("test.conf") as stream
    stream = StringIO("[env]\n" + stream.read())
    config.readfp(stream)
    for item in config.items('env'):
        print(item)

If I print the config value I read it prints as follows with an extra backslash.

('path', 'Dtest.appender\\=console')

Why does this happen? How can I solve this problem?

Moon Cheesez
  • 2,489
  • 3
  • 24
  • 38
user3451476
  • 297
  • 1
  • 4
  • 17
  • 2
    "it *prints* as follows": because that is the representation of an (escaped) backslash in a string. –  Jun 16 '16 at 01:42
  • Try printing the single element inside the tuple instead. –  Jun 16 '16 at 01:45
  • @Evert I tried printing it in a tuple. It just prints the same. I want to know if the config values have changed or if python prints raw strings like that – user3451476 Jun 16 '16 at 02:03
  • 1
    The value has not changed, Evert is correct. The way to represent a backslash in Python is with two backslashes due to escaping. – hichris123 Jun 16 '16 at 02:05
  • @Evert Can you take a look at this link http://stackoverflow.com/questions/37843165/design-a-python-api-for-existing-java-api?noredirect=1#comment63153623_37843165 – user3451476 Jun 16 '16 at 02:26
  • Your link points to a comment on a question (asked by you) about "Design a Python API for existing Java API". Sure I'll take a look, but it absolutely makes no sense to me with regards to this question (other than being from the same author). –  Jun 16 '16 at 05:44
  • @Evert It's not related to this question. But your inputs on that could be helpful. Thank you – user3451476 Jun 16 '16 at 17:42

0 Answers0