test = "TOML"
[section]
key = "value_section" # セクションのバリュー
list = ["value1", "value2"] # セクションのバリュー
#dict.key = ["value", inner_dict = "inner_dict"]
dict.key = "value"
dict.inner_dict = "inner_dict"
### yamlだとこう
# dict:
# key: "value"
# inner: "value"
[sec]
key = "value_sec" # セクションのバリュー
list = ["value1", "value2"] # セクションのバリュー
#dict.key = ["value", inner_dict = "inner_dict"]
dict.key = "value"
dict.inner_dict = "inner_dict"
# need python
pip install toml
pip install pathlib # option
piip install python-box # option
python exec_toml.py
# {'test': 'TOML', 'section': {'key': 'value_section', 'list': ['value1', 'value2'], 'dict': {'key': 'value', 'inner_dict': 'inner_dict'}}, 'sec': {'key': 'value_sec', 'list': ['value1', 'value2'], 'dict': {'key': 'value', 'inner_dict': 'inner_dict'}}}
# ver2
python exec_toml.py | jq
: <<PRINT
{
"key": "value_sec",
"list": [
"value1",
"value2"
],
"dict": {
"key": "value",
"inner_dict": "inner_dict"
}
}
PRINT
import toml
from pathlib import Path
from box import Box
gettoml = Box(toml.loads(Path("test.toml").open().read())))
print(gettoml)
# jqコマンドに渡したい場合、json.dumpsで' -> "に変換する
# ver2
import json
print(json.dumps(gettoml.section))
# need python
pip install toml
pip install pathlib # option
piip install python-box # option
python exec_toml.py
# {'test': 'TOML', 'section': {'key': 'value_section', 'list': ['value1', 'value2'], 'dict': {'key': 'value', 'inner_dict': 'inner_dict'}}, 'sec': {'key': 'value_sec', 'list': ['value1', 'value2'], 'dict': {'key': 'value', 'inner_dict': 'inner_dict'}}}
# ver2
python exec_toml.py | jq
: <<PRINT
{
"key": "value_sec",
"list": [
"value1",
"value2"
],
"dict": {
"key": "value",
"inner_dict": "inner_dict"
}
}
PRINT
test = "TOML"
[section]
key = "value_section" # セクションのバリュー
list = ["value1", "value2"] # セクションのバリュー
#dict.key = ["value", inner_dict = "inner_dict"]
dict.key = "value"
dict.inner_dict = "inner_dict"
### yamlだとこう
# dict:
# key: "value"
# inner: "value"
[sec]
key = "value_sec" # セクションのバリュー
list = ["value1", "value2"] # セクションのバリュー
#dict.key = ["value", inner_dict = "inner_dict"]
dict.key = "value"
dict.inner_dict = "inner_dict"
import toml
from pathlib import Path
from box import Box
gettoml = Box(toml.loads(Path("test.toml").open().read())))
print(gettoml)
# jqコマンドに渡したい場合、json.dumpsで' -> "に変換する
# ver2
import json
print(json.dumps(gettoml.section))