473,513 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

showing help(M) when running module M standalone

hello,
I have a small module which only contains some utility functions. when
running this standalone I would like to show the module docs and each
function docs, as if doing

import M
help(M)

I came up with the following but I reckon there is a much simpler way?

if __name__ == '__main__':
print __doc__
print "\nFUNCTIONS:\n"
for x in __all__:
print x
exec "print " + x + ".__doc__"

Works but does not seem right using exec for such a task.

any hint would be great!

thanks
chris
Jul 30 '05 #1
7 1126
On Sat, 30 Jul 2005 17:04:50 +0200,
Chris <c@cdot.de> wrote:
hello,
I have a small module which only contains some utility functions. when
running this standalone I would like to show the module docs and each
function docs, as if doing import M
help(M) I came up with the following but I reckon there is a much simpler way? if __name__ == '__main__':
print __doc__
print "\nFUNCTIONS:\n"
for x in __all__:
print x
exec "print " + x + ".__doc__" Works but does not seem right using exec for such a task.
So don't use exec.
any hint would be great!


for x in __all__:
print x.__doc__

HTH,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
Jul 30 '05 #2
Chris wrote:
hello,
I have a small module which only contains some utility functions. when
running this standalone I would like to show the module docs and each
function docs, as if doing

import M
help(M)

I came up with the following but I reckon there is a much simpler way?

if __name__ == '__main__':
print __doc__
print "\nFUNCTIONS:\n"
for x in __all__:
print x
exec "print " + x + ".__doc__"

Works but does not seem right using exec for such a task.


One way would be to use the locals() [1] to get rid of the exec:

if __name__ == '__main__':
print __doc__
print "\nFUNCTIONS:\n"
for x in __all__:
print x
print locals()[x].__doc__
However, if you just want to call help, calling it on '__main__' seems
to work:

if __name__ == '__main__':
help(__name__)
[1] http://docs.python.org/lib/built-in-funcs.html
Jul 30 '05 #3
Chris <c@cdot.de> writes:
hello,
I have a small module which only contains some utility functions. when
running this standalone I would like to show the module docs and each
function docs, as if doing

import M
help(M)

I came up with the following but I reckon there is a much simpler way?

if __name__ == '__main__':
print __doc__
print "\nFUNCTIONS:\n"
for x in __all__:
print x
exec "print " + x + ".__doc__"

Works but does not seem right using exec for such a task.

any hint would be great!


if __name__ == "__main__":
help("__main__")

The only downside is that the module name is printed as '__main__'.

Thomas
Jul 30 '05 #4
hello,
thanks for all suggestions,

if __name__ == '__main__':
__name__ = 'MODULENAME'
help(__name__)

does actually work any even shows the modulename it should.

chris
Jul 30 '05 #5
Dan Sommers wrote:
On Sat, 30 Jul 2005 17:04:50 +0200,
Chris <c@cdot.de> wrote:

hello,
I have a small module which only contains some utility functions. when
running this standalone I would like to show the module docs and each
function docs, as if doing
import M
help(M)


I came up with the following but I reckon there is a much simpler way?


if __name__ == '__main__':
print __doc__
print "\nFUNCTIONS:\n"
for x in __all__:
print x
exec "print " + x + ".__doc__"


Works but does not seem right using exec for such a task.

So don't use exec.

any hint would be great!

for x in __all__:
print x.__doc__


I tried that, problem is that __all__ containts strings...

HTH,
Dan

Jul 30 '05 #6
On Sat, 30 Jul 2005 22:02:49 +0200,
Chris <c@cdot.de> wrote:
I tried that, problem is that __all__ containts strings...


Oops. <sheepish grin>

I should have looked before I lept.

Sorry,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
Jul 31 '05 #7
On Sat, 30 Jul 2005 22:02:49 +0200,
Chris <c@cdot.de> wrote:
I tried that, problem is that __all__ containts strings...


Okay, that's twice I've lept before I looked. How about this:

for a in __all__:
print globals()[a].__doc__

HTH,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
Jul 31 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1508
by: Fahd Khan | last post by:
The web-based Python software I've written thus far lacks a consistent approach to generating output. After reading Graham Fawcett's endorsement of Zope Template Pages in the recent web programming...
7
8771
by: pysim | last post by:
Hi, I have a couple of general requests for pointers to python examples and design advice. I'm looking for examples of MVC-based GUI controls done in python (model-view-controller). Also,...
1
3856
by: Marc | last post by:
Hello, I've fiddled with this for quite a while and thought I had the problem solved. I had a version that would successfully compile and run. But then I had to change the code to use a...
10
2183
by: svenn.are | last post by:
Hi, I wanted to run a program that is written in PyQt on my mac, and went over to Riverbank to get PyQ 3.13 and SIP 4.1.1 sources. I followed the installation guide except for the compiling...
8
5452
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
6
1705
by: David | last post by:
I am using ADO to run some SQL statements in Access. First, I run query to create a table using SELECT . . . INTO Table A. Then, I run a query to SELECT . . . FROM Table A to get some data and...
0
1693
by: Page | last post by:
I have a C# system service that is marked as interactive and use local system account (default) and marked to automatically start. When I restart the system the application is not visible. When...
1
3694
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
2
2491
by: martoncho | last post by:
Hi all, I am facing what is for me a really complicated situation. I program C but not this advanced (I mean direct hardware access etc). Here is the background: I am using DJGPP. I am...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.