diff --git a/docs/appendix/01_use_cases.md b/docs/appendix/01_use_cases.md new file mode 100644 index 0000000..c117f5b --- /dev/null +++ b/docs/appendix/01_use_cases.md @@ -0,0 +1,16 @@ +# Python 用例索引 +为了方便大家索引内容,我们将我们这套教程中的相关使用用例通过索引的方式列出来了。 + +因为 MD 文件格式的局限性,我们没有办法在这里帮助大家进行一一解答和讨论,所以我们将解答和用例放到了 [WWW.OSSEZ.COM](https://www.ossez.com) 平台下 Python 分类中。 + +请访问: https://www.ossez.com/c/open-source/python/14 参与讨论,我会在这里等着大家。 + +## 索引链接 +请通过索引的链接快速参与讨论了解更多详细的内容。 + +### 语言基础 +针对语言的基础,请访问下面的的链接中的内容。 + +| 文章标题 | 简要介绍 | +|---|---| +| [Python With 关键字和语句](https://www.ossez.com/t/python-with/13387) | 针对 with 关键字的使用进行了一些解答。 | diff --git a/tests/FileWith.py b/tests/FileWith.py new file mode 100644 index 0000000..b989bb5 --- /dev/null +++ b/tests/FileWith.py @@ -0,0 +1,17 @@ +# Python script to Read file from JSON and convert to YAML +# Author - HoneyMoose (https://www.ossez.com) + +import json + +json_filename = 'resources/honeymoose_test.json' + +# Read and process JSON +with open(json_filename) as json_file: + data = json.load(json_file) + print(type(data)) + + for data_dict in data: + label_id = data_dict['label_id'] + print(str(label_id)) + +print(json_file.closed) diff --git a/tests/Json2Yaml.py b/tests/Json2Yaml.py new file mode 100644 index 0000000..b16b4a7 --- /dev/null +++ b/tests/Json2Yaml.py @@ -0,0 +1,23 @@ +# Python script to Read file from JSON and convert to YAML +# Author - HoneyMoose (https://www.ossez.com) + +import json +import ruamel.yaml as yaml + +json_filename = 'resources/black_rock_test.json' +yaml_filename = 'resources/black_rock_test.yaml' + +# Read and process JSON +with open(json_filename) as json_file: + data = json.load(json_file) + print(type(data)) + + for data_dict in data: + label_id = data_dict['label_id'] + print(str(label_id)) +json_file.close() + +# Write to YAML +yaml_file = open(yaml_filename, 'w+') +yaml.dump(data, yaml_file, allow_unicode=True) +yaml_file.close() diff --git a/tests/Keywords.py b/tests/Keywords.py index 4c23962..75f556f 100644 --- a/tests/Keywords.py +++ b/tests/Keywords.py @@ -2,6 +2,7 @@ # Author - https://www.ossez.com import keyword +import json print(keyword.kwlist) print(len(keyword.kwlist)) diff --git a/tests/resources/black_rock_test.json b/tests/resources/black_rock_test.json new file mode 100644 index 0000000..b608e34 --- /dev/null +++ b/tests/resources/black_rock_test.json @@ -0,0 +1,10 @@ +[ + { + "label_id": 603, + "user_name": "YUCHENG-L1" + }, + { + "label_id": 604, + "user_name": "YUCHENG-L2" + } +] \ No newline at end of file diff --git a/tests/resources/honeymoose_test.json b/tests/resources/honeymoose_test.json new file mode 100644 index 0000000..b608e34 --- /dev/null +++ b/tests/resources/honeymoose_test.json @@ -0,0 +1,10 @@ +[ + { + "label_id": 603, + "user_name": "YUCHENG-L1" + }, + { + "label_id": 604, + "user_name": "YUCHENG-L2" + } +] \ No newline at end of file