Я пытаюсь изучить python, и я приземлился на
with..as
который используется следующим образом:
with open("somefile.txt", 'rt') as file:
print(file.read())
# at the end of execution file.close() is called automatically.
Итак, как стратегия обучения, я попытался сделать следующее:
class Derived():
def __enter__(self):
print('__enter__')
def __exit__(self, exc_type, exc_value, traceback):
print('__exit__')
with Derived() as derived:
print(derived)
и я получил этот вывод:
__enter__
None
__exit__
Мой вопрос:
- Почему
print(derived)
возвращает объектNone
, а не объектDerived
?