why does "help(import)" not work?

  • Thread starter Robert P. J. Day
  • Start date
R

Robert P. J. Day

i'm sure there's a painfully obvious answer to this, but is there a
reason i can't do:
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.

what is the rule for this in python3?

rday
--


========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
========================================================================
 
D

Diez B. Roggisch

Robert said:
i'm sure there's a painfully obvious answer to this, but is there a
reason i can't do:

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.

what is the rule for this in python3?

import is a keyword, so the parser can't comprehend the expression you
created. In the same way it can't do it for


help(class)

or

help(def)


or any other keyword.

Diez
 
B

Bruno Desthuilliers

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:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top