Categories
How to fix Attribute Error?
>>> with 1 as one: ... print(one) ... Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: __enter__
Answer the question
In order to leave comments, you need to log in
No way. 1 is an instance of the int class that does not support the context manager protocol, i.e. cannot be used with the with statement. Only classes that describe the __enter__() and __exit__() magic methods can be used with this operator.
Didn't find what you were looking for?
Ask a Question
731 491 924 answers to any question