O GoConqr está de visual novo! Conte para nós o que você achou.

Flashcards

python beyond context manager

Andrew Sperazza python Inglês 10 flashcards

Flashcards do conjunto (10)

  1. 1what is a context manageran object designed to be used in a with statement
  2. 2what methods are used by a context manager2 methods (enter and exit)
    with context-manager:
    enter()
    ///body///
    exit()
    __enter__(self)
    and
    __exit__(self,exc_type,exc_val,exc_tb)
  3. 3given the following code: with myexpression as x: body what must myexpression do?myexpression must evaluate to a context manager, in other words, it must produce an object that implements:
    __enter__()
    and
    __exit__ ()
    methods
  4. 4what is bound to x : with myexpression as x:the return value of the __enter__() method
  5. 5in __exit__() context manager method, what is exc_type, exc_val, and exc_tb ?exc_type is exception type
    exc_val is exception object
    exc_tb is exception traceback
  6. 6how can you see if there was an exception thrown in a context managerinside __exit__( self, exc_type, exc_val, exc_tb )
    check exc_type for something other than None to see if exception was thrown
  7. 7what is a standard library for working with context managers?contextlib
  8. 8what is the decorator inside contextlib that can be used to create new context managerscontextlib.contextmanager
  9. 9what is the general code outline for a context manager using contextlib.contextmanager@contextlib.contextmanager
    def my_context_manager():
    #
    try: '
    yield [value]
    #
    except: '
    #
    raise '
  10. 10can you use multiple context manager?>yes
    with cm1() as a, cm2() as b, ...:
    BODY

Informações

Descrição
python (beyond basics python flashcards) FlashCards sobre python beyond context manager, criado por Andrew Sperazza em 12-01-2017.
Criado por
Andrew Sperazza
Visualizações
1
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?