How to load toml file in python
Asked Answered
P

2

5

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 micheal"
    age = 25
Peace answered 14/1, 2023 at 3:30 Comment(0)
P
7

it can be used without open as a file

import toml


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

print(data["first"]["name"])
Peace answered 14/1, 2023 at 3:37 Comment(0)
M
1
import toml

with open("file.toml", "r") as f:
    data = toml.load(f)

print(data["first"]["name"])
Muslin answered 14/1, 2023 at 3:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.