Hi,
Based on ConfigParser module how can I filter out and throw every comments from an ini file?
import ConfigParser
config = ConfigParser.ConfigParser()
config.read("sample.cfg")
for section in config.sections():
print section
for option in config.options(section):
print option, "=", config.get(section, option)
eg. ...
I want to save a set of key, value pairs (string, int) between runs of a Python program, reload them on subsequent runs and write the changes to be available on the next run.
I don't think of this data as a configuration file, but it would fit the ConfigParser capabilities quite well. I would only need two [sections]. It's only a few hu...
I have the following:
config = ConfigParser()
config.read('connections.cfg')
sections = config.sections()
How can I close the file opened with config.read?
In my case, as new sections/data are added to the config.cfg file, i update my wxtree widget, however, it only updates once, and i suspect it's because config.read leaves the file...
I've noticed with my source control that the content of the output files generated with ConfigParser is never in the same order. Sometimes sections will change place or options inside sections even without any modifications to the values.
Is there a way to keep things sorted in the configuration file so that I don't have to commit trivi...
When using ConfigParser module I would like to use values containing of multiple words set in cfg file. In this case seems trivial for me to surround the string with quotes like (example.cfg):
[GENERAL]
onekey = "value in some words"
My problem is that in this case python appends the quotes to the string as well when using the value l...
Hi,
Actually I am stuck in my work. I want to import a txt file into my python program which should have two lists of intergers.
The following program is working fine but I need to import the list 'a' and 'b' with the help of configparser.
It will be so nice if some one help me with it!
I am a begineer in python so please try to ans...
I've tried to use python's ConfigParser module to save settings. For my app it's important that I preserve the case of each name in my sections. The docs mention that passing str() to ConfigParser.optionxform() would accomplish this, but it doesn't work for me. The names are all lowercase. Am I missing something?
<~/.myrc contents>
[rul...
Hi all,
my troubles with ConfigParser continue. It seems it doesn't support Unicode very well. The config file is indeed saved as UTF-8, but when ConfigParser reads it it seems to be encoded into something else. I assumed it was latin-1 and I thougt overriding optionxform could help:
-- configfile.cfg --
[rules]
Häjsan = 3
☃ = my snowm...
I am working on a series of command line tools which connect to the same server and do related but different things. I'd like users to be able to have a single configuration file where they can place common arguments such as connection information that can be shared across all the tools. Ideally, I'd like something that does the follow...
Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort?
Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and is really annoying to edit manually a huge unsorted config file.
PD: I'm using python 2...
I'm using ConfigParser to load in data from a configuration file as follows:
test.conf:
[myfiles]
fileone: %(datadir)s/somefile.foo
filetwo: %(datadir)s/nudderfile.foo
load.py:
import ConfigParser
config = ConfigParser.ConfigParser({'datadir': '/tmp'})
config.read('test.conf')
print config.items('myfiles')
print config.get('myfile...
Hi, I have a config file that I read using the RawConfigParser in the standard ConfigParser library. My config file has a [DEFAULT] section followed by a [specific] section. When I loop through the options in the [specific] section, it includes the ones under [DEFAULT], which is what is meant to happen.
However, for reporting I wanted ...
I have the following ini file
[Section]
value=test
When i use the ConfigParser Module :
import ConfigParser
config = ConfigParser.ConfigParser()
config.read('config.ini')
str=config.get('Section', 'value')
if str == 'test':
print 1
else :
print 0
it always print 0 could someone help
...
I am making a plugin for another program and so I am trying to make thing as lightweight as possible.
What i need to do is be able to update the name of a section in the ConfigParser's config file.
[project name]
author:john doe
email: [email protected]
year: 2010
I then have text fields where user can edit project's name, author, em...
Hi,
I have a python class which reads a config file using ConfigParser:
Config file:
[geography]
Xmin=6.6
Xmax=18.6
Ymin=36.6
YMax=47.1
Python code:
class Slicer:
def __init__(self, config_file_name):
config = ConfigParser.ConfigParser()
config.read(config_file_name)
# Rad the lines from the file
...
In the config file I have the varible defined as
BackgroundColor = 0,0,0
Which should work for the screen.fill settings for Pygame or any color argument for that matter. Where I can just do screen.fill(0,0,0)
The problem I think is with this is that for integers read through a configfile I have to put int() to convert the string to a...
I have a script/program I am working on that requires a configuration file (I am using ConfigParser). On linux, I will default to store these variables in ~/.myscript using the os.getenv('HOME') function.
With Windows, I know I can use os.getenv('USERPROFILE') to find the User's "home" directory, however, is it a good idea to save a ...
The documentation for ConfigParser in Python talks a lot about the so-called "magical interpolation" feature, but never explains what it actually does. I've tried searching for it, but haven't found any answers.
...
Which is better for creating a settings file for Python programs, the built-in module (ConfigParser), or the independent project (ConfigObj)?
...
Which is better for creating a settings file for Python programs, the built-in module (ConfigParser) or the independent project (ConfigObj), or using the YAML data serialization format? I have heard that ConfigObj is easier to use than ConfigParser, even though it is not a built-in library. I have also read that PyYAML is easy to use, ...