config

How to properly read and write .cfg files through python

How to properly read and write .cfg files through python Question: I need help with reading and writing to .cfg files in Python. The .cfg files that I want to read and write have a specific format which cannot be changed. An example .cfg file: [META] title = "Xxxx xxxx" creator = "xxx" artist = …

Total answers: 2

AttributeError: type object 'ConfigParser' has no attribute 'Error'

AttributeError: type object 'ConfigParser' has no attribute 'Error' Question: from configparser import ConfigParser configfile = ‘config.ini’ cparser = ConfigParser() try: # assigns values from config except ConfigParser.Error as e: print(e) This code was working a day ago, i dont know if i changed something and it messed things up, but it no longer works Traceback …

Total answers: 1

Dynamically calling and assigning a variable from a config python files

Dynamically calling and assigning a variable from a config python files Question: I have a list of parameters in a config file, if a specific model file is called in my script I want to dynamically assign the appropriate parameters to the variable name config file looks like this: tune_model_selection = [‘logreg_module’, ‘random_forest_module’] logreg_module_tune_parameter_grid = …

Total answers: 1

using variable (f)-string stored in json

using variable (f)-string stored in json Question: I have a json config file where I store my path to data there The data is bucketed in month and days, so without the json I would use an f-string like: spark.read.parquet(f"home/data/month={MONTH}/day={DAY}") Now I want to extract that from json. However, I run into problems with the …

Total answers: 2

Which part should the package configuration in Python script?

Which part should the package configuration in Python script? Question: I have few code which set the configuration for logging and package setting. pd.set_option(‘display.max_columns’, None) logging.getLogger("urllib3").setLevel(logging.ERROR) Where should I put these into the script (under import, under if __name__ == "__main__", etc) or can I create a configuration file for setting configuration? import pybit import …

Total answers: 1

How to write a .cfg file with ":" instead of "=" in python

How to write a .cfg file with ":" instead of "=" in python Question: I’m using python3 ConfigParser, my code is conf = configparser.ConfigParser() cfg_file = open(‘./config.cfg’, ‘w’) conf.set(None, ‘a’, ‘0’) conf.write(cfg_file) cfg_file.close() I expected the result to be a : 0 in the config.cfg file. However, I got a = 0. Is there a …

Total answers: 1

How to assign variable for every line in txt seperately in Python?

How to assign variable for every line in txt seperately in Python? Question: I have a text file that with multiple lines and I’m trying to assign turn every line into a string and assign them into a variable separately. The code looks something like this at the moment: with open(‘config.txt’, ‘r’) as f: file_name …

Total answers: 3

How to receive input parameters in various python scripts through a common json file

How to receive input parameters in various python scripts through a common json file Question: I have the following json input parameters file #input.json { "nx": 401, "ny": 401, "T" : 10, "nt" : 20, "D" : 0.2, "Sgma": 0.243, "M": 0.0052 } that is passed onto different python scripts, for eg. #test1.py import numpy,os …

Total answers: 1

Testing with configuration files

Testing with configuration files Question: my Google-fu has failed me by giving me results I don’t understand, so I’m asking here. I’m working on a Python project and I currently have a configuration file, which is also .py, that holds various python objects to load when everything starts. I’m trying to get some practice unit …

Total answers: 2