AttributeError: ‘module’ object has no attribute ‘GetoptError’

If you are new to Python and trying some examples on the net, you might come across with this error as I did. I was trying the getopt module example at

When I tried to run the code I got the below output.

The code was as below.

I didn’t understand in the beginning but later on I realized that the problem was with the file name. If you put the file name as I did, you will get the AttributeError. Just change the file name and remove the Byte-compiled getopt.pyc file which has just been created and try to run your code again.