LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   AttributeError: 'module' object has no attribute 'error' (http://www.linuxquestions.org/questions/programming-9/attributeerror-module-object-has-no-attribute-error-718052/)

cmnorton 04-09-2009 05:03 PM

AttributeError: 'module' object has no attribute 'error'
 
I am puzzled as to why this program is throwing an

AttributeError: 'module' object has no attribute 'error'

This example is right out of

http://www.artima.com/weblogs/viewpost.jsp?thread=4829

I would appreciate any thoughts as to what the problem might be.
tnx
cmn

#!/usr/bin/python
"""Module docstring.

This serves as a long usage message.
"""

import sys
import getopt

def main():
# parse command line options
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
except getopt.error, msg:
print msg
print "for help use --help"
sys.exit(2)
# process options
for o, a in opts:
if o in ("-h", "--help"):
print __doc__
sys.exit(0)
# process arguments


if __name__ == "__main__":
main()

Hko 04-09-2009 05:45 PM

Quote:

Originally Posted by cmnorton (Post 3503999)
I am puzzled as to why this program is throwing an

AttributeError: 'module' object has no attribute 'error'

I tried the program and on my python installation it doesn't throw any excpetion...

This is on Python 2.5.2.

What version of python did you use?
Is your python installation messed up?
Since on your system it does no throw an error on importing getopt, but then later it does on getopt.error.

That makes me think there could be something wrong with your getopt module. Or an incompatible version or so.

BTW would you please use post code inside [ code ] and [ /code ] tags? On python code this is even more important than any other programming language, since indention matters with python.


All times are GMT -5. The time now is 03:53 AM.