如何在python中加载toml文件

Mar*_*sfy 5 python toml

如何将 toml 文件加载到我的代码的 python 文件中

蟒蛇文件:

import toml 


toml.get("first").name
Run Code Online (Sandbox Code Playgroud)

.toml 文件:

[first]
    name = "Mark Wasfy"
    age = 22
[second]
    name = "john micheal"
    age = 25
Run Code Online (Sandbox Code Playgroud)

Mar*_*sfy 6

无需作为文件打开即可使用

import toml


data = toml.load("./config.toml")

print(data["first"]["name"])
Run Code Online (Sandbox Code Playgroud)