why does "help(import)" not work?
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Fri Nov 6 05:12:38 EST 2009
Robert P. J. Day a écrit :
> i'm sure there's a painfully obvious answer to this, but is there a
> reason i can't do:
>
>>>> help(import)
Yes, there's a very painfully obvious reason : 'import' is a statement,
'help' is a function, and you can't (syntactically) pass a statement as
an argument to function !-)
> File "<stdin>", line 1
> help(import)
> ^
> SyntaxError: invalid syntax
>
> on the other hand, i can certainly go into "help()" and type
> "import" to get that help. it seems counter-intuitive to have the
> first variation fail but the second succeed.
Would you find it more "intuitive" to have different syntactic rules for
the interactive shell ?-)
FWIW, the way to get help on a statement (or on a non-already defined
name) is to pass a string to help, ie:
help("import")
HTH
More information about the Python-list
mailing list