L
L
link_vrb2021-10-03 14:35:53
Python
link_vrb, 2021-10-03 14:35:53

How to fix Attribute Error?

>>> with 1 as one:
...     print(one)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: __enter__

This is an error code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-10-03
@link_vrb

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 your question

Ask a Question

731 491 924 answers to any question