some changing
This commit is contained in:
38
test.py
38
test.py
@@ -167,30 +167,24 @@ class Commands:
|
||||
|
||||
@staticmethod
|
||||
async def write_json(guild: int, param_name: str, param: str or int):
|
||||
with open('prefix.json', 'r', encoding='utf-8') as _f:
|
||||
_jsonObject = json.load(_f)
|
||||
with open('prefix.json', 'r') as _f:
|
||||
try:
|
||||
_guild_conf = _jsonObject[f"{guild}"]
|
||||
except KeyError:
|
||||
_guild_conf = {}
|
||||
try:
|
||||
_param = _guild_conf[f"{param_name}"]
|
||||
except KeyError:
|
||||
_param = {}
|
||||
print(f'json is {_jsonObject}\n type {type(_jsonObject)}'
|
||||
f' Guild is {guild}\n type {type(_param)}'
|
||||
f' Param name is {param_name}\n type {type(_param)}'
|
||||
f' param is {param} type {type(_param)}')
|
||||
_new_param = {f"{param_name}": f'{param}'}
|
||||
_new_guild = {f"{guild}": {}}
|
||||
_jsonObject.update(_new_guild)
|
||||
_guild_conf = _jsonObject[f"{guild}"]
|
||||
print(f"Guild conf is: {_guild_conf}")
|
||||
_param.update(_new_param)
|
||||
print(f"Param is: {_param}")
|
||||
_guild_conf.update(_param)
|
||||
_jsonObject = json.load(_f)
|
||||
except json.JSONDecodeError:
|
||||
_jsonObject = {}
|
||||
try:
|
||||
_guild_conf = _jsonObject[f'{guild}']
|
||||
except KeyError as error:
|
||||
_guild_conf = {f'{guild}': {}}
|
||||
try:
|
||||
_param = _guild_conf[f"{param_name}"]
|
||||
|
||||
with open("prefix.json", "w") as _f:
|
||||
except KeyError:
|
||||
_param = {f'{param_name}': f'{param}'}
|
||||
|
||||
_jsonObject.update(_guild_conf)
|
||||
print(_jsonObject)
|
||||
with open('prefix.json', 'w') as _f:
|
||||
json.dump(_jsonObject, _f)
|
||||
_f.close()
|
||||
|
||||
|
||||
41
test2.py
41
test2.py
@@ -2,37 +2,16 @@ import json
|
||||
|
||||
|
||||
def write_json(guild: int, param_name: str, param: str or int):
|
||||
with open('prefix.json', 'r+', encoding='utf-8') as _f:
|
||||
with open('prefix.json', 'r', 'utf-8') as _f:
|
||||
try:
|
||||
_jsonObject = json.load(_f)
|
||||
_json = json.load(_f)
|
||||
except json.decoder.JSONDecodeError:
|
||||
_jsonObject = {}
|
||||
_json = {}
|
||||
_json.update({f'{guild}': {}})
|
||||
print(_json)
|
||||
_guild = _json[f'{guild}']
|
||||
print(_guild)
|
||||
_guild.update({f'{param_name}': f'{param}'})
|
||||
print(_json)
|
||||
|
||||
try:
|
||||
_guild_conf = _jsonObject[f"{guild}"]
|
||||
except KeyError:
|
||||
_guild_conf = {f"{guild}": {}}
|
||||
|
||||
print(_jsonObject)
|
||||
print(_jsonObject)
|
||||
|
||||
try:
|
||||
_param = {f"{param_name}": f"{param}"}
|
||||
except KeyError:
|
||||
_param = {f"{param_name}": f"{param}"}
|
||||
print(_param)
|
||||
|
||||
_guild_conf.update(_param)
|
||||
print(_jsonObject)
|
||||
_jsonObject.update(_guild_conf)
|
||||
_guild_conf = _jsonObject[f"{guild}"]
|
||||
print(_jsonObject)
|
||||
print(_guild_conf)
|
||||
print(_param)
|
||||
|
||||
with open("prefix.json", "w") as _f:
|
||||
json.dump(_jsonObject, _f)
|
||||
_f.close()
|
||||
|
||||
|
||||
write_json(929446191270330452, 'rr', '34')
|
||||
write_json(929446191270330452, 'test1', '34')
|
||||
|
||||
23
test3.py
Normal file
23
test3.py
Normal file
@@ -0,0 +1,23 @@
|
||||
my_dict = {'key': 'value'}
|
||||
print(my_dict)
|
||||
|
||||
my_dict.update({'another_key': 'another_value'}) # Дополняем.
|
||||
print(my_dict)
|
||||
my_dict.update({'another_key': 'yet_another_value'}) # Обновляем.
|
||||
print(my_dict)
|
||||
my_dict.update({"subdict": {}})
|
||||
subdict = my_dict['subdict']
|
||||
print(my_dict)
|
||||
print(subdict)
|
||||
subdict.update({'subdictkey': 'subdictvalue'})
|
||||
print(subdict)
|
||||
|
||||
print(my_dict)
|
||||
subdict.update({'subdictkey2': 'subdictvalue2'})
|
||||
print(my_dict)
|
||||
subdict.update({'subdictkey': '33'})
|
||||
|
||||
print(my_dict)
|
||||
my_dict.update({'testKey': 'testValue'})
|
||||
print(my_dict)
|
||||
print(my_dict)
|
||||
Reference in New Issue
Block a user