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 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/>
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
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
hello,
thanks for all suggestions,
if __name__ == '__main__':
__name__ = 'MODULENAME'
help(__name__)
does actually work any even shows the modulename it should.
chris
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
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/>
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/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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,...
|
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...
|
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...
|
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
--------------------------------------------------------------------------------
...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |