An AttributeError
is raised when I use the example code from python's documentation (here). The example code is as follows:
with os.scandir(path) as it:
for entry in it:
if not entry.name.startswith('.') and entry.is_file():
print(entry.name)
The result is an AttributeError
:
D:\Programming>test.py
Traceback (most recent call last):
File "D:\Programming\test.py", line 3, in <module>
with os.scandir() as it:
AttributeError: __exit__
Although, assigning os.scandir()
to a variable works fine.
Could someone tell me what I'm missing?