2016-11-24 4 views
0
私は、configファイルの読み取りには、次のコードを使用してい

パイソンのConfigParser無効な構文

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

ファイルは次のようになります。

[Server] 
port = 9012 
workspace = doc/ 

をしかし、私は次のエラーを取得する:

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

どうすれば修正できますか?

答えて

1

設定ファイルをPythonスクリプトのように実行しようとしているようです。エラーを再現する方法は次のとおりです。

C:\Users\Luke\StackOverflow>python config.cfg 
    File "config.cfg", line 3 
    workspace = doc/ 
       ^
SyntaxError: invalid syntax