configparser

ConfigParser and String interpolation with env variable

ConfigParser and String interpolation with env variable Question: it’s a little bit I’m out of python syntax and I have a problem in reading a .ini file with interpolated values. this is my ini file: [DEFAULT] home=$HOME test_home=$home [test] test_1=$test_home/foo.csv test_2=$test_home/bar.csv Those lines from ConfigParser import SafeConfigParser parser = SafeConfigParser() parser.read(‘config.ini’) print parser.get(‘test’, ‘test_1’) does …

Total answers: 9

Write to lowercase 'default' section ConfigParser

Write to lowercase 'default' section ConfigParser Question: I am working with an ini file where the default section is named ‘default’ and not ‘DEFAULT’. Pythons ConfigParser seams to handle these sections ok with no problem. However, for whatever reason, they dont allow you to add a ‘default’ section or write to it. In the code, …

Total answers: 3

How to read config from string or list?

How to read config from string or list? Question: Is it possible to read the configuration for ConfigParser from a string or list? Without any kind of temporary file on a filesystem OR Is there any similar solution for this? Asked By: Lucas || Source Answers: You could use a buffer which behaves like a …

Total answers: 3

Python ConfigParser Checking existence of both Section and Key Value

Python ConfigParser Checking existence of both Section and Key Value Question: Using ConfigParser’s has_section() method I can check if a section exists in a file, such as: config.has_section(section_name) What would be a command to check if a key exists as well? So it would be possible to verify that both a section and key exists …

Total answers: 1

tkinter and configparser : looking for a more beautiful solution

tkinter and configparser : looking for a more beautiful solution Question: I want to use config.ini‘s values as startup values for Tkinter Entry items. When the program is finished, I want to write the content of these Entry into the config.ini. I have 2 problems with the following code : # create the Entry textboxes …

Total answers: 1

python ConfigParser read file doesn't exist

python ConfigParser read file doesn't exist Question: import ConfigParser config = ConfigParser.ConfigParser() config.read(‘test.ini’) This is how we read a configuration file in Python. But what if the ‘test.ini’ file doesn’t exist? Why doesn’t this method throw an exception? How can I make it throw exception if the file doesn’t exist? Asked By: Cacheing || Source …

Total answers: 2

How to access the variables declared inside functions in python

How to access the variables declared inside functions in python Question: I have the following code that reads the configuration file and stores the results in some variables as a list import ConfigParser def read_config_file(): config = ConfigParser.ConfigParser() cnf_path = ‘config_files/php.sr’ config.read(cnf_path) if config.has_section(‘basic’): if config.has_option(‘basic’, ‘basic’): php_bsc_mdls = config.get(‘basic’, ‘basic’).split(‘,’) if config.has_section(‘advance’): if config.has_option(‘advance’,’advance’): …

Total answers: 3

MissingSectionHeaderError: File contains no section headers

MissingSectionHeaderError: File contains no section headers Question: I am trying to build collective.simserver according to this manual, with some modifications: instead of: virtualenv –python=bin/python2.7 simserver/ I am using: virtualenv –python=myVirtualEnv/bin/python simserver and I managed to come to this point: myVirtualEnv/bin/python bootstrap.py and then it breaks apart with this error info: An internal error occurred due …

Total answers: 5

Booleans in ConfigParser always return True

Booleans in ConfigParser always return True Question: This is my example script: import ConfigParser config = ConfigParser.ConfigParser() config.read(‘conf.ini’) print bool(config.get(‘main’, ‘some_boolean’)) print bool(config.get(‘main’, ‘some_other_boolean’)) And this is conf.ini: [main] some_boolean: yes some_other_boolean: no When running the script, it prints True twice. Why? It should be False, as some_other_boolean is set to no. Asked By: user1447941 …

Total answers: 2

Python ConfigParser: Checking for option existence

Python ConfigParser: Checking for option existence Question: I’m using Python’s ConfigParser to create a configuration file. I want to check if a section has a particular option defined and, if it does, get the value. If the option isn’t defined, I just want to continue without any special behavior. There seem to be two ways …

Total answers: 1