【发布时间】:2023-01-14 11:46:21
【问题描述】:
如何将toml文件加载到python文件中 我的代码
蟒蛇文件:
import toml
toml.get("first").name
toml文件:
[first]
name = "Mark Wasfy"
age = 22
[second]
name = "john micheal"
age = 25
【问题讨论】:
如何将toml文件加载到python文件中 我的代码
蟒蛇文件:
import toml
toml.get("first").name
toml文件:
[first]
name = "Mark Wasfy"
age = 22
[second]
name = "john micheal"
age = 25
【问题讨论】:
import toml
with open("file.toml", "r") as f:
data = toml.load(f)
print(data["first"]["name"])
【讨论】:
它可以在不作为文件打开的情况下使用
import toml
data = toml.load("./config.toml")
print(data["first"]["name"])
【讨论】: