say I am reading a json file.
save_list = []
json_path = '../business.json'
js = [json.loads(line) for line in open(json_path)]
for item in js:
save_dict = {}
try:
save_dict['name'] = item['name']
save_dict['neighborhood'] = item['neighborhood']
save_dict['city'] = item['city']
The problem is in json file, some lines
have no value for 'city' or 'name', which are noise data, but I don't want to remove them. I want to write a exception that can handle this none value, if there is no value, put a none to the value, the save_dict['city'] = none
, same as save_dict['name'] = none
. How do I write try: exception:
?