do_with.py 267 B

1234567891011121314
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from contextlib import contextmanager
  4. @contextmanager
  5. def log(name):
  6. print('[%s] start...' % name)
  7. yield
  8. print('[%s] end.' % name)
  9. with log('DEBUG'):
  10. print('Hello, world!')
  11. print('Hello, Python!')