0

Let's say I have a package omegaproject I'm importing from a script test.py:

test.py
omegaproject/
  __init__.py
  omega.py

Say that in __init__.py I've put """Hello there""" and nothing else.

Now, say that test.py consists of:

import omegaproject 

print(omegaproject.__doc__)

Shouldn't running test.py cause Python to display 'Hello there'? Instead, it displays nothing.

In other words, where do I specify the docstring of a package?

3
  • 2
    That's exactly how it works, but you are apparently not importing the correct package. Validate that you are indeed importing what you think you are by printing omegaproject.__file__. Commented Aug 21, 2014 at 22:01
  • if you import omegaproject and use omegaproject.__doc__ from an ipython or a python shell, what happens? Commented Aug 21, 2014 at 22:08
  • You're right Martijn, it does work. I had drawn up my example to simplify from my actual situation but did not actually test it before posting this question. Now as I try to figure out how my actual situation differs from the simplified example, I'm having a hard time replicating the issue. So never mind. Sorry! Commented Aug 21, 2014 at 22:37

1 Answer 1

1

Let's call this a "trick question" :)

As Martijn points out, in fact the docstring does appear as desired.

The problem was in this sequence of events:

  1. I originally had __init__.py empty.
  2. Then I ran test.py, which printed nothing.
  3. Then I edited __init__.py to have a docstring reading """Hello there"""
  4. Then on the interactive shell I ran: import omegaproject followed by omegaproject.__doc__

But omegaproject had already been imported! So the second import did nothing, the docstring did not get updated, and so the docstring was still showing as blank.

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

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.