Last active
October 15, 2018 08:52
-
-
Save shimajima-eiji/cd5056b37c538132cd532bfdadb9a186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
{ | |
"key": "value_sec", | |
"list": [ | |
"value1", | |
"value2" | |
], | |
"dict": { | |
"key": "value", | |
"inner_dict": "inner_dict" | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment