GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

python beyond context manager

Andrew Sperazza python Englisch 10 Karten

Karten in diesem Stapel (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

Informationen

Beschreibung
python (beyond basics python flashcards) Karteikarten am python beyond context manager, erstellt von Andrew Sperazza am 12/01/2017.
Erstellt von
Andrew Sperazza
Aufrufe
1
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck