python - ConfigParser - print config.sections() returns [] -


i'm trying use configparser module parse *.ini file. problem when try print sections or whatever, returns empty list [].

config.ini

[server] host=localhost port=9999 max_clients=5 [regular_expressions] regular_expressions_file_path=commands/commands_dict 

config.py

# -*- coding: utf-8 -*-  import configparser  config = configparser.safeconfigparser() config.read("config.ini") print config.sections() 

[]

do know problem?

edit: here screen of structure:enter image description here

your code works me. sure cwd points right directory right config.ini file in it?

$ cat config.ini [server] host=localhost port=9999 max_clients=5 [regular_expressions] regular_expressions_file_path=commands/commands_dict  $ python2.7 python 2.7.10 (default, aug 22 2015, 20:33:39) [gcc 4.2.1 compatible apple llvm 7.0.0 (clang-700.0.59.1)] on darwin type "help", "copyright", "credits" or "license" more information. >>> import configparser >>> cp = configparser.safeconfigparser() >>> cp.read('config.ini') ['config.ini'] >>> cp.sections() ['server', 'regular_expressions'] >>> ^d 

Comments