1

I try to use doctest from example from http://docs.python.org/library/doctest.html

But when I run

python example.py -v

I get this

Traceback (most recent call last):
  File "example.py", line 61, in <module>
    doctest.testmod()
AttributeError: 'module' object has no attribute 'testmod'

But I can import doctest in python interactive shell and enable to use doctest.testmod() as well. I searched in google and didn't find the solution.

Python version is 2.5.1 on Max OSX

2 Answers 2

5

Clearly the doctest module object you have at hand at that point is NOT the normal, unadulterated one you get from an import doctest from the standard library. Printing doctest.__file__ (and sys.stdout.flush()ing after that, just to make sure you do get to see the results;-) before the line-61 exception will let you know WHERE that stray doctest module is coming from.

If you show us example.py as well as that output we can probably point out what exactly you may be doing wrong, if it doesn't already become obvious to you.

Sign up to request clarification or add additional context in comments.

2 Comments

Very thanks! It's because that I named the script as doctest.py before, and it doesn't work so I changed to example.py. But doctest.pyc is still there then doctest.pyc is imported instead.
Python will recompile the pyc if that's required and possible, but, yes, if it has the pyc and no source for it, then it will just use the existing pyc file.
0

Try inserting a

print doctest, dir(doctest)

before line 61. This will tell you the location of the doctest module, and what attributes it has. You can do this to make sure that there's nothing wrong with your doctest module.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.