Reputation:
If I have the following directory structure:
handy/
- __init__.py
- utils.py
- dir1
- __init__.py
- script.py
I can populate DATA
in help()
by writing non-keywords into the __init__.py
file, for example:
# __init__.py
hello = "xyz"
other = "z"
variables = 1
Now when I do help(handy), it shows:
DATA
hello = 'xyz'
other = 'z'
variables = 1
Are there any other ways to populate the help DATA
from outside of the top-level __init__.py
file, or is that the only way?
Upvotes: 1
Views: 40
Reputation: 123473
I'm not sure what you have in mind, but since handy/__init__.py
is an executable script, you could do something like this:
__init__.py
:
from .utils import *
hello = "xyz"
other = "z"
variables = 1
utils.py
:
UTILS_CONSTANT = 42
def func():
pass
Which would result in:
>>> import handy
>>> help(handy)
Help on package handy:
NAME
handy
PACKAGE CONTENTS
utils
DATA
UTILS_CONSTANT = 42
hello = 'xyz'
other = 'z'
variables = 1
FILE
c:\stack overflow\handy\__init__.py
>>>
to what help(handy)
displays.
Upvotes: 1