quality = job['data']['fields']['quality']
my_file = open(os.path.join(pathToTmpDir, 'quality.json'), 'w')
my_file.write(quality)
my_file.close()
try:
quality = job['data']['fields']['quality']
except KeyError:
quality='2222'
except TypeError:
quality='1111'
else:
if quality == '':
quality='33333'
else:
quality = job['data']['fields']['quality']
my_file = open(os.path.join(pathToTmpDir, 'quality.json'), 'w')
my_file.write(quality)
my_file.close()
try:
quality = job['data']['fields']['quality']
error = False
except KeyError:
error = True
print('''KeyError: quality''', file=sys.stderr)
except TypeError:
error = True
print('''Type mismatch in assigning to quality!''', file=sys.stderr)
if not error:
my_file = open(os.path.join(pathToTmpDir, 'quality.json'), 'w')
my_file.write(quality)
my_file.close()
error
можно писать и тип ошибки и его обрабатывать после блока try .. except