corrlib/corrlib/tools.py
Justus Kuhlmann d104d994f8
Some checks failed
Mypy / mypy (push) Failing after 45s
Pytest / pytest (3.12) (push) Failing after 48s
Pytest / pytest (3.14) (push) Failing after 45s
Ruff / ruff (push) Failing after 33s
Pytest / pytest (3.13) (push) Failing after 48s
correct typing errors
2025-12-04 11:49:52 +01:00

33 lines
773 B
Python

import os
from configparser import ConfigParser
from typing import Any
def str2list(string: str) -> list[str]:
return string.split(",")
def list2str(mylist: list[str]) -> str:
s = ",".join(mylist)
return s
cached: bool = True
def m2k(m: float) -> float:
return 1/(2*m+8)
def k2m(k: float) -> float:
return (1/(2*k))-4
def set_config(path: str, section: str, option: str, value: Any) -> None:
config_path = os.path.join(path, '.corrlib')
config = ConfigParser()
if os.path.exists(config_path):
config.read(config_path)
if not config.has_section(section):
config.add_section(section)
config.set(section, option, value)
with open(config_path, 'w') as configfile:
config.write(configfile)
return