43 lines
1.0 KiB
Python
43 lines
1.0 KiB
Python
import json
|
|
import sys
|
|
|
|
def read_config(config_file, key_path):
|
|
"""
|
|
Read a value from JSON config file.
|
|
|
|
Args:
|
|
config_file: Path to JSON config file
|
|
key_path: Dot-separated path to the key (e.g., "evaluation.checkpoint_path")
|
|
|
|
Returns:
|
|
The value at the specified key path
|
|
"""
|
|
with open(config_file, 'r') as f:
|
|
json_config = json.load(f)
|
|
|
|
# Navigate through nested keys
|
|
keys = key_path.split('.')
|
|
value = json_config
|
|
for key in keys:
|
|
if isinstance(value, dict):
|
|
value = value.get(key)
|
|
else:
|
|
return None
|
|
|
|
return value
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 3:
|
|
print("Usage: python read_config.py <config_file> <key_path>", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
config_file = sys.argv[1]
|
|
key_path = sys.argv[2]
|
|
|
|
value = read_config(config_file, key_path)
|
|
if value is not None:
|
|
print(value)
|
|
else:
|
|
print("", file=sys.stderr)
|
|
sys.exit(1)
|