BOOKPYTHON Telegram 3081
Порядок блоков except имеет значение: если исключение может быть поймано несколькими блоками, то его поймает верхний блок. Этот код не будет работать так, как задумано


import logging

def get(storage, key, default):
try:
return storage[key]
except LookupError:
return default
except IndexError:
return get(storage, 0, default)
except TypeError:
logging.exception('unsupported key')
return default

print(get([1], 0, 42)) # 1
print(get([1], 10, 42)) # 42
print(get([1], 'x', 42)) # error msg, 42


👉@BookPython
👍2



tgoop.com/BookPython/3081
Create:
Last Update:

Порядок блоков except имеет значение: если исключение может быть поймано несколькими блоками, то его поймает верхний блок. Этот код не будет работать так, как задумано


import logging

def get(storage, key, default):
try:
return storage[key]
except LookupError:
return default
except IndexError:
return get(storage, 0, default)
except TypeError:
logging.exception('unsupported key')
return default

print(get([1], 0, 42)) # 1
print(get([1], 10, 42)) # 42
print(get([1], 'x', 42)) # error msg, 42


👉@BookPython

BY Библиотека Python разработчика | Книги по питону




Share with your friend now:
tgoop.com/BookPython/3081

View MORE
Open in Telegram


Telegram News

Date: |

Ng was convicted in April for conspiracy to incite a riot, public nuisance, arson, criminal damage, manufacturing of explosives, administering poison and wounding with intent to do grievous bodily harm between October 2019 and June 2020. While the character limit is 255, try to fit into 200 characters. This way, users will be able to take in your text fast and efficiently. Reveal the essence of your channel and provide contact information. For example, you can add a bot name, link to your pricing plans, etc. The SUCK Channel on Telegram, with a message saying some content has been removed by the police. Photo: Telegram screenshot. Hui said the messages, which included urging the disruption of airport operations, were attempts to incite followers to make use of poisonous, corrosive or flammable substances to vandalize police vehicles, and also called on others to make weapons to harm police. ZDNET RECOMMENDS
from us


Telegram Библиотека Python разработчика | Книги по питону
FROM American