Search code examples
pythontoml

How to load toml file in python


How to load toml file into a python file that my code

python file:

import toml 


toml.get("first").name

toml file :

[first]
    name = "Mark Wasfy"
    age = 22
[second]
    name = "John Wasfy"
    age = 25

Solution

  • it can be used without open as a file

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