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
17
votes
5 answers

Converting ConfigParser values to python data types

ConfigParser requires all sections, keys and values to be strings; no surprise. It has methods to convert the values to datatypes with getfloat, getint, getboolean. If you don't know the datatype, you can wrap the get() with an eval() to get have…
tMC
  • 18,105
  • 14
  • 62
  • 98
16
votes
4 answers

Parsing configure file with same section name in python

I try to parse file like: [account] User = first [account] User = second I use ConfigParser in Python, but when i read file: Config = configparser.ConfigParser() Config.read(file) print (Config.sections()) I have error: While reading from ... :…
ExyTab
  • 527
  • 3
  • 7
  • 14
16
votes
4 answers

reading special characters text from .ini file in python

I am running a script which takes a text "rAh%19u^l\&G" i.e which contains special characters as seen. When i pass this text in my script as a argument it runs fine without any error. example - : ./abc.py The above text is basically…
Rahul Gupta
  • 201
  • 2
  • 4
  • 10
16
votes
5 answers

How to handle empty values in config files with ConfigParser?

How can I parse tags with no value in an ini file with python configparser module? For example, I have the following ini and I need to parse rb. In some ini files rb has integer values and on some no value at all like the example below. How can I do…
AKM
  • 6,285
  • 9
  • 31
  • 34
15
votes
4 answers

Closing file opened by ConfigParser

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…
sqram
  • 7,069
  • 8
  • 48
  • 66
15
votes
2 answers

Getting a list from a config file with ConfigParser

I have something like this in my config file (a config option that contains a list of strings): [filters] filtersToCheck = ['foo', '192.168.1.2', 'barbaz'] Is there a more elegant (built-in) way to get a list from filtersToCheck instead of removing…
tkit
  • 8,082
  • 6
  • 40
  • 71
15
votes
3 answers

How to use variables already defined in ConfigParser

I'm using ConfigParser in Python config.ini is [general] name: my_name base_dir: /home/myhome/exp exe_dir: ${base_dir}/bin Here I want exp_dir becomes /home/myhome/exp/bin not ${base_dir}/bin. It means ${base_dir} would be substituted to…
emesday
  • 6,078
  • 3
  • 29
  • 46
15
votes
2 answers

Modify INI file with Python

I have an INI file I need to modify using Python. I was looking into the ConfigParser module but am still having trouble. My code goes like this: config=…
Kreuzade
  • 757
  • 5
  • 11
  • 22
14
votes
1 answer

Having trouble reading AWS config file with python configparser

I ran aws configure to set my access key ID and secret access key. Those are now stored in ~/.aws/credentials which looks like: [default] aws_access_key_id = ###### aws_secret_access_key = ####### I'm trying to access those keys for a script I'm…
April Polubiec
  • 598
  • 5
  • 13
14
votes
4 answers

Section postgresql not found in the database.ini file

I'm trying to create tables in my database (postgresql 9.6) and when I launch my python script to do so, it returns me an error of the following type: "Section postgresql not found in the $FILEDIR/database.ini file" It seems like the parser cannot…
Fatmajk
  • 1,770
  • 1
  • 13
  • 22
14
votes
6 answers

Python configparser getting and setting without exceptions

Everytime you try to get or set to a section using configparser in Python it throws a NoSectionError if the section does not exist. Is there anyway to avoid this? Also, can I also avoid the NoOptionError when getting an option? For example, using a…
Nick Humrich
  • 14,905
  • 8
  • 62
  • 85
13
votes
1 answer

Python: ConfigParser.NoSectionError: No section: 'TestInformation'

I am getting ConfigParser.NoSectionError: No section: 'TestInformation' error using the above code. def LoadTestInformation(self): config = ConfigParser.ConfigParser() print(os.path.join(os.getcwd(),'App.cfg')) with…
Loganswamy
  • 257
  • 2
  • 5
  • 14
11
votes
3 answers

Configparser Integers

I am not sure what I am doing wrong. Previously, the code was this: volume = min(60, max(30, volume)) However, after trying with configparser, I keep getting a 500 error on my Twilio Server. volume_min = configParser.get('config_searchandplay',…
Ace NA
  • 121
  • 1
  • 2
  • 8
11
votes
7 answers

How to read properties file in python

I have a property file called Configuration.properties containing: path=/usr/bin db=mysql data_path=/temp I need to read this file and use the variable such as path, db, and data_path in my subsequent scripts. Can I do this using configParser or…
Deepika Soren
  • 181
  • 2
  • 3
  • 12
10
votes
1 answer

How do I set a value to None with ConfigParser?

I'm using ConfigParser in Python 2.7 to read from a config file and I'm wondering how to read a value such that it's set to the constant None in Python. Currently, my code is as follows: config.set("Test Series Parameters", "Test Series Parameter",…
Parth
  • 1,226
  • 7
  • 28
  • 49
1 2
3
45 46