[Tutor] concerning help() function

Wayne srilyk at gmail.com
Wed Jul 29 14:39:32 CEST 2009


On Wed, Jul 29, 2009 at 1:29 AM, David <ldl08 at gmx.net> wrote:

> Dear Tutors,
>
> whenever I make use of the help() function, I have a good chance of
> getting an error. I have not yet understood this tool very well.
>
> Take the modules operator and random as examples. The former is
> built-in, the latter not.
> Do I wish to see the help files, I have to use a different syntax:
>
> help(random)
> help('operator')
>
> I figured this by trial and error, and I am keen to find out when the
> help() function is to be supplied with a string, and when no '' is
> required. It certainly does not seem intuitive to me!


>>> operator
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'operator' is not defined
>>> help('operator')

>>> random
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'random' is not defined
>>> help(random)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'random' is not defined
>>> help('random')
(produces the helpfile)

This goes back to pythons objects. If something is an object in python, you
can probably pass it to help(), otherwise you need to pass a string.

>>> operator = 'foo'
>>> help(operator)
         Welcome to ASCII Assassin!
                 (1) Start Game
                 (2) Instructions

:>

I guess that's an easter egg... so I'm off to play ASCII Assassin!

HTH,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090729/42cc0190/attachment.htm>


More information about the Tutor mailing list