1

I'm using the following code to read a config file:

def get_config():
    c = configparser.ConfigParser()
    c.read("config.cfg")
    return c.options("Server")

The file looks like this:

[Server]
port = 9012
workspace = doc/

But I get the following error:

  File "config.cfg", line 3
    workspace = doc/
                   ^
SyntaxError: invalid syntax

What's causing this and how can I fix it?

1 Answer 1

2

It seems you are trying to run the configuration file as if it were a Python script. Here's one way to reproduce your error:

C:\Users\Luke\StackOverflow>python config.cfg
  File "config.cfg", line 3
    workspace = doc/
                   ^
SyntaxError: invalid syntax
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.