【发布时间】:2022-07-26 17:31:40
【问题描述】:
我想构建一个将 fstring 格式存储在配置文件中的工具。
config = load_config()
def build_fstring(str):
return ... # <-- issue is there
chosen_format = config.get("chosen_format") # returns '{k},{v}'
fstring = build_fstring(chosen_format) # may return something like 'f"{k},{v}"'
for (k,v) in d.items():
print(fstring) # fstring is evaluated here
我的问题是 fstring 在变量已知之前编译。
有办法吗?
【问题讨论】: