Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

AttributeError: __enter__ python

# cause A
# don't forget to return self
def __enter__(self):
    # do stuff
    return self

# cause B
# forgetting to "call" the class when using it in the "with X as Y" format
with classFoo as X: # from
with classFoo() as X: # to
  
# cause C
# forgetting to create an "__exit__" function
def __exit__(self, exc_type, exc_val, exc_tb):
    # do stuff to finsh up
 
PREVIOUS NEXT
Tagged: #python
ADD COMMENT
Topic
Name
1+3 =