Reputation: 1142
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
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