473,569 Members | 2,526 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 1132
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.tombstoneze ro.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.tombstoneze ro.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.tombstoneze ro.net/dan/>
Jul 31 '05 #8

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

Similar topics

3
1509
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 thread, I looked up TAL and found it to be quite nice. Going through recent postings on Google it seems SimpleTAL is the standalone TAL module in...
7
8778
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, examples where something like a simulation model running in its own thread sends fast updates to a GUI in near real-time. The only examples I've seen,...
1
3860
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 different module, and now it will compile but not run again. I know that functionality in this area is not fully supported yet, but there has to be...
10
2194
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 python as Macosx already has python. I had no problem with compiling SIP and also no problem with compiling PyQt nor did I have any error message...
8
5459
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I...
6
1709
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 the table is empty. This appears to be a timing issue because the second query works when I run it in ACCESS instead of in VB following the...
0
1713
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 I log into the administrators account there it is running with no issues. This is a standalone kiosk application and need to run in the...
1
3698
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 attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am...
2
2499
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 programming a DOS program that will play wave files on certain functions (moving through the menus, running functions, etc) Today's motherboards come with...
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.