NotADirectoryError

Built-in ExceptionPython 2.0+Intermediate

Raised when a directory operation is attempted on a non-directory

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
# Triggering and catching NotADirectoryError
try:
    raise NotADirectoryError("not a directory")
except NotADirectoryError as e:
    print(f"Caught NotADirectoryError: {e}")
    print(f"Type: {type(e).__name__}")

NotADirectoryError is raised when raised when a directory operation is attempted on a non-directory. Always catch specific exceptions rather than bare except clauses.

Try in Playground

Tags

exceptionerror-handlingcore