How to Solve NameError: name 'OptionParser' is not defined -- optparse

Solution: Import the 'OptionParser' module

# Add the following line to the top of your code
from optparse import OptionParser

 

For more information:
optparse OptionParser