Questions tagged [configparser]

ConfigParser is a Python module for reading and writing configuration files that have a structure similar to those of INI files in Microsoft Windows.

683 questions
2
votes
2 answers

ConfigParser does not load sections when run via crontab

When I run python script via command line, everything works just perfect, but wehn the script is being running from cron ConfigParser creates an empty list of sections me = singleton.SingleInstance() ######### Accessing the configuration file…
Edik Mkoyan
  • 309
  • 2
  • 17
2
votes
1 answer

Edit ini file option values with ConfigParser (Python)

Anyone know how'd I'd go about editing ini file values preferably using ConfigParser? (Or even a place to start from would be great!) I've got lots of comments throughout my config file so I'd like to keep them by just editing the values, not taking…
avacariu
  • 2,780
  • 3
  • 25
  • 25
2
votes
3 answers

Python: Configparser - escape newlines?

Is there a way to escape newlines using ConfigParser? There is this option --addons-path in config where you can provide multiple paths for addons, but paths are long and there are many of paths so writing everything in one line, looks really bad.…
Andrius
  • 19,658
  • 37
  • 143
  • 243
2
votes
2 answers

regular expression Pattern object getting converted to string if fetched from config.cfg file

python file import ConfigParser,re config=ConfigParser.ConfigParser() with open("temp.cfg",'r') as config_file: config.readfp(config_file) x=[] x.append(re.compile(r'abc')) x.append((config.get("ssp",'a')).strip('"')) print x[0] print…
Ravi Yadav
  • 405
  • 4
  • 16
2
votes
3 answers

configparser loading config files from zip

I am creating a program that loads and runs python scripts from a compressed file. Along with those python scripts, I have a config file that I previously used configparser to load info from in an uncompressed version of the program. Is it possible…
Marshall
  • 73
  • 6
2
votes
1 answer

How to use ConfigParser to extract an unknown number of value pairs?

In this question, the OP wanted to extract an unknown number of sections from a config file using ConfigParser, where all of the sections shared the same internal format. In my case, I'm constrained to keep everything confined to one section. I'm…
smitelli
  • 6,835
  • 3
  • 31
  • 53
2
votes
0 answers

Python config parser raises exception for one value but not others

I have the following method: def PopulateStaticDetails(args): confParser = ConfigParser.SafeConfigParser() confParser.read(args.configFile) generator = '' emails = '' certType = '' # ---- Cert Server Check ---- # if…
MrDuk
  • 16,578
  • 18
  • 74
  • 133
2
votes
2 answers

Editing ini file using python "ConfigParser" will replace all ini entries to lower keys

The code snippet below can edit an ini file, but will replace all ini entries to lower case: config = ConfigParser.RawConfigParser() config.read("test.ini") config.set("GENERAL", "OptionEntry4", "100") with open("test.ini", 'w') as configfile: …
2
votes
2 answers

python ConfigParser: read configuration from string

I would like to parse a configuration string that I receive from a service and read each single paramenter. The string result is [section 1],var1 = 111,var2 = 222 My code: #!/usr/bin/python import ConfigParser import io [...] result =…
d82k
  • 379
  • 7
  • 17
2
votes
3 answers

How to store formatted strings in a configuration file?

I am using the ConfigParser module in Python 2.6 and I wish to load formatted strings from my configuration file. An example of such a string might be the following: [Section Name] #in the config file #tmp_string has value 'string' my_string = 'This…
2
votes
1 answer

Include logging configuration in file read by configparser

I use configparser to read some configuration options for my application and I'd like to read the logging configuration as well. Can I do that in the same file? How should I name the logging specific sections?
lilorox
  • 155
  • 2
  • 12
2
votes
1 answer

How to get case-sensitivity in Section names?

I've got an win32 app accessed by users via RDP acess. Each user has his/her own user_app.ini file. When I upgrade my app on the RDP server, I sometimes need to create/modify entries in the user_app.ini file of each user. I wrote a Python script to…
Sun Wukong
  • 154
  • 10
2
votes
3 answers

Pythonic reading from config files

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() …
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
2
votes
3 answers

Write to lowercase 'default' section ConfigParser

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…
Nick Humrich
  • 14,905
  • 8
  • 62
  • 85
2
votes
1 answer

ConfigParser.MissingSectionHeaderError when reading config file Python

I am trying to read some values from a config file params.txt using ConfigParser in Python but keep getting a MissingSectionHeadError I have a file params.txt: [all] zigzag = 0.08 fractal = 0.03 rng_length = 1000 stp = 100 and the following…
baconwichsand
  • 1,161
  • 2
  • 13
  • 31