【问题标题】:How to load toml file in python如何在python中加载toml文件
【发布时间】: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

【问题讨论】:

    标签: python toml


    【解决方案1】:
    import toml
    
    with open("file.toml", "r") as f:
        data = toml.load(f)
    
    print(data["first"]["name"])
    

    【讨论】:

      【解决方案2】:

      它可以在不作为文件打开的情况下使用

      import toml
      
      
      data = toml.load("./config.toml")
      
      print(data["first"]["name"])
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-11-05
        • 2021-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多