How to Solve NameError: name 'listdir' is not defined -- os

Solution: Import the 'listdir' module

To Solve the error, add the following line to the top of your code.

from os import listdir

 

For more information:
Python os listdir