why does "help(import)" not work?

Chris Rebert clp2 at rebertia.com
Fri Nov 6 05:36:14 EST 2009


On Fri, Nov 6, 2009 at 2:28 AM, Robert P. J. Day <rpjday at crashcourse.ca> wrote:
> On Fri, 6 Nov 2009, Chris Rebert wrote:
>
>> On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day <rpjday at crashcourse.ca> wrote:
>> >  i'm sure there's a painfully obvious answer to this, but is there a
>> > reason i can't do:
>> >
>> >>>> help(import)
>> >  File "<stdin>", line 1
>> >    help(import)
>> >              ^
>> > SyntaxError: invalid syntax
>> >>>>
>
>> It would take a hideous kludge to make help(import) work.
>
>  um ... ok, i'll take your word for it, but is there at least a
> generalizable pattern for what is directly help()able and what isn't?

Language keywords aren't help()-able:
http://docs.python.org/reference/lexical_analysis.html#keywords

Neither are punctuation/operators (see other sections on same webpage).

help() is run-of-the-mill function, no different than any other, is
not treated specially, and doesn't perform magic.
You can't pass raw syntax elements to functions (whether the functions
are built-in or user-defined).

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list