Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'help' function not showing info about imported functions

Tags:

python

Suppose I have 2 files: main.py and test.py. The contents of test.py are

def say(name):
     return name

The main.py contains a single line from test import *

My question is the following: when I import main.py from REPL and run help(main), I want to see 'say' function as an output, but that doesn't happen. Is there any way I can accomplish this? Thanks.

like image 366
dfridman1 Avatar asked Sep 06 '25 22:09

dfridman1


1 Answers

You can use dir(main) to list all the names in a module including those imported from other modules.

Notice, only members owned by the module are shown in help(). Nevertheless, you can force your module to take ownership of imported names by explicitely indexing your module with the magic module property __all__.

Make the contents of main.py to be:

from test import *
__all__ = ['say']
like image 149
Salva Avatar answered Sep 09 '25 12:09

Salva