Python supercharged for fastai development
56
Build a configuration file reader that can load settings from multiple configuration files located in different directories without permanently changing the program's working directory.
Your task is to implement a configuration loader that:
config.ini fileThe implementation should ensure that the main program's working directory is never permanently changed, even when reading files from multiple different locations.
def load_configs(config_dirs: list[str]) -> dict:
"""
Load and merge configuration files from multiple directories.
Args:
config_dirs: List of directory paths containing config.ini files
Returns:
Dictionary containing merged configuration values
"""
passGiven directories ['./dir1', './dir2'] where dir1/config.ini contains key1=value1 and dir2/config.ini contains key2=value2, the function returns {'key1': 'value1', 'key2': 'value2'} @test
Given directories ['./dir1', './dir2'] where both contain config.ini files with the same key key1, dir1 has key1=value1 and dir2 has key1=value2, the function returns {'key1': 'value2'} (later directory wins) @test
The original working directory is preserved after calling the function, even after reading from multiple directories @test
Given a directory path that doesn't exist, the function skips it and continues processing other directories @test
@generates
Provides working directory context management utilities.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/pypi-fastcoredocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10