Re: showing help(M) when running module M standalone

2005-07-30 Thread Dan Sommers
On Sat, 30 Jul 2005 22:02:49 +0200,
Chris <[EMAIL PROTECTED]> 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://mail.python.org/mailman/listinfo/python-list


Re: showing help(M) when running module M standalone

2005-07-30 Thread Dan Sommers
On Sat, 30 Jul 2005 22:02:49 +0200,
Chris <[EMAIL PROTECTED]> wrote:

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

Oops.  

I should have looked before I lept.

Sorry,
Dan

-- 
Dan Sommers

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: showing help(M) when running module M standalone

2005-07-30 Thread Chris
hello,
thanks for all suggestions,

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

does actually work any even shows the modulename it should.

chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: showing help(M) when running module M standalone

2005-07-30 Thread Chris
Dan Sommers wrote:
> On Sat, 30 Jul 2005 17:04:50 +0200,
> Chris <[EMAIL PROTECTED]> 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
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: showing help(M) when running module M standalone

2005-07-30 Thread Thomas Heller
Chris <[EMAIL PROTECTED]> 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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: showing help(M) when running module M standalone

2005-07-30 Thread tiissa
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: showing help(M) when running module M standalone

2005-07-30 Thread Dan Sommers
On Sat, 30 Jul 2005 17:04:50 +0200,
Chris <[EMAIL PROTECTED]> 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://mail.python.org/mailman/listinfo/python-list


showing help(M) when running module M standalone

2005-07-30 Thread Chris
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
-- 
http://mail.python.org/mailman/listinfo/python-list