ConfigParser is a Python module for reading and writing configuration files that have a structure similar to those of INI files in Microsoft Windows.
Questions tagged [configparser]
683 questions
1
vote
4 answers
Reading a fortigate configuration file with Python
Appologies for the really long drawn out question.
I am trying to read in a config file and get a list of rules out.
I have tried to use ConfigParser to do this but it is not a standard config file.
The file contains no section header and no…

Alex
- 21
- 1
- 5
1
vote
0 answers
Use variables parsed from config files in SQL query
Here is how the variables are parsed from the config file :
soc_code = tuple(config.get('MyScript', 'soc_code').split(','))
genre_code = tuple(config.get('MyScript', 'genre_code').split(','))
Here is my sql query :
sql_query = pd.read_sql_query('''…

MDUB77
- 65
- 5
1
vote
1 answer
Python logging file config with variable directory
I'm using Python logging and loading it with logging.config.fileConfig(config_file), from e.g. logging.cfg. It contains a TimedRotatingFileHandler. It works great. For a long time it has been using…

Halvor Holsten Strand
- 19,829
- 17
- 83
- 99
1
vote
1 answer
Wrapping a method from outside the class in Python with decorator
I would like to ask a question, how I can override/extend the existing external python class. I wanted to be able to call the same API, like parent class, but with some modifications.
Something like that:
[a]
b = 1
import configparser
# my wrapper…

Andy
- 74
- 9
1
vote
0 answers
ConfigParser printing config to string with TOML/ini format
I'm trying to use ConfigParser to edit a string that stores a .ini file content.
To import the string I use ConfigParser.read_string(my_string).
what I'm looking for is the exact opposite function so I can later set my string's value as content of…

Orili
- 11
- 2
1
vote
2 answers
Python: Working with configparser inside a class. How to access my attributes names and values dynamically inside my class-methods
My first program is getting much bigger than excepted. :)
import configparser
config = configparser.ConfigParser()
configfile = 'RealGui.ini'
class FolderLeftSettings:
def __init__(self):
self.name = "SECTION"
…

Leonick
- 45
- 7
1
vote
1 answer
.getboolean() NoOptionError
I was trying to read a boolean value using config parser, It finds the section fine but it fails finding the option for some reason.
configparser.NoOptionError: No option 'firsttime' in section: 'DEFAULT'
In the INI i have:
[DEFAULT]
"firsttime" =…

Lexi
- 9
- 4
1
vote
1 answer
Configparser python giving error while trying to access any value [Python]
I am using configparser to store username and password for a project I am developing. The file Info.ini has the following:
[Username]
user1 = Admin
[Password]
user1 =
[Other]
firsttimeopen = True
The idea here is that, if firsttimeopen = True,…

Speedy
- 50
- 8
1
vote
1 answer
launch Django project from any folder
In my project I use config file which is one level higher than manage.py.
I use ConfigParser to read it, but for Django to run correctly I need to be in the directory where manage.py is
Here is the part where the magic should happen
import os
import…

muhammed hilal
- 91
- 6
1
vote
1 answer
How to retrieve key, value from config.ini?
i want to read certain data from a config file as key,value
i found below way to define the key value in config.ini
[Section]
value={"name":"John","id":"101"}
but not seeing the way to parse this value as dictionary in python
i actually need to…

Adhi cloud
- 39
- 6
1
vote
2 answers
configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%s %s'
I am trying to read from ini file and replace it with os environment variables.
My ini file:
[svc1]
host=%(TEST_IP)s
port=%(TEST_PORT)s
database=test_db
user=test
connect_timeout=3
My python file:
from configparser import ConfigParser
import…

Amogh M K
- 43
- 6
1
vote
2 answers
execute a function inside another function
I have this configuration file (test_conf.txt):
[function]
exptime1 = |def foo(f):
| result=float(f['a'])
| return result
and this code that works without problem
c =…

Astrom
- 767
- 5
- 20
1
vote
1 answer
ConfigParser read Booleans / String / Integer at the same time with Python
Here is my config.ini:
[LOADER]
text = example text
size = 17
settings = None
run = False
But when I print it, using:
config = ConfigParser()
config.read('config.ini')
print(config._sections['LOADER'])
I get this:
{'text': 'example text', 'size':…

Tibo1211
- 37
- 5
1
vote
0 answers
Reading and writing configuration files from multiple modules
I'm writing a program to read comics with a feature to switch between single-page and double-page view. I'm storing this value (and others) inside a config.ini file, like this:
[settings]
double_view = False
And change it trough a button in my…

Eaguilar
- 19
- 2
1
vote
1 answer
How to include paths in a Python user configuration file that is installed with setuptools (data_files)?
I have a project with the following structure:
myproject/
data/
src/
myproject/
tests/
setup.py
config.ini
pyproject.toml
…

Chris Hubley
- 311
- 2
- 9