Jonas Kohl
Jonas Kohl

Reputation: 1142

Python ConfigParser Invalid Syntax

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?

Upvotes: 1

Views: 1502

Answers (1)

Luke Woodward
Luke Woodward

Reputation: 64959

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

Upvotes: 2

Related Questions