Обложка канала

Библиотека Python разработчика

20835 @BookPython

Библиотека Python разработчика. Книги по программированию на Python.

Библиотека Python разработчика

4 года назад
Открыть в
If you want to catch both IndexError and KeyError, you may and should use LookupError, their common ancestor. It proved to be useful while accessing complex nested data: try: db_host = config['databases'][0]['hosts'][0] except LookupError: db_host = 'localhost'