33 lines
773 B
Python
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
|