# 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
with ParamExample(URI) as pe, MotionCommander(pe, default_height=0.3) as mc:
This is the peice of code which had AttributeError: __enter__
with sr.Microphone as source:
It got resolved by adding '()' as below:
with sr.Microphone() as source: