>>> help(import)
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
========================================================================
import is a keyword, not an object.
--
Cheers,
Simon B.
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
"Special cases aren't special enough to break the rules."
-- Zen of Python (http://www.python.org/dev/peps/pep-0020/)
It would take a hideous kludge to make help(import) work.
Cheers,
Chris
--
http://blog.rebertia.com
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
help() is just a regular function that must be called with correct
Python syntax and the import keyword is not allowed in an argument list.
The correct syntax is:
help('import')
Cheers,
Brian
On 6 Nov 2009, at 20:56, Robert P. J. Day 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
>>>>
>
> 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
> =
> =
> ======================================================================
> On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day <rpj...@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.
>
> Cheers,
> Chris
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?
rday
--
========================================================================
> Hi Robert,
>
> help() is just a regular function that must be called with correct
> Python syntax and the import keyword is not allowed in an argument
> list.
>
> The correct syntax is:
> help('import')
ah, ok, now it makes sense. so python3 just lets me be sloppy about
it, as in:
>>> help(print)
got it.
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).
> On Fri, 6 Nov 2009, Chris Rebert wrote:
>
> > On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day <rpj...@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.
> >
> > Cheers,
> > Chris
>
> 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?
never mind, i was just educated on the proper usage of help(). i
*knew* i was going to embarrass myself when i asked that. :-P back
to reading.
If it's an object (or to be precise, a name bound to an object), it's
helpable. If it's a keyword, it's not - and in fact can't be, since as
you've found, it's a syntax error - so you fall back to passing a
string.
--
Cheers,
Simon B.
print is a function in Python 3, so that's fine. In Python 2, that
would also be a syntax error.
--
Cheers,
Simon B.
> On Fri, 6 Nov 2009, Brian Quinlan wrote:
>
>> Hi Robert,
>>
>> help() is just a regular function that must be called with correct
>> Python syntax and the import keyword is not allowed in an argument
>> list.
>>
>> The correct syntax is:
>> help('import')
>
> ah, ok, now it makes sense. so python3 just lets me be sloppy about
> it, as in:
>
> >>> help(print)
>
> got it.
In python 3 print is a function.
No, "print" is a function in python3, not a statement as it is in
earlier versions. There's nothing sloppy about it, and nothing in
help has changed from 2 to 3: if it's a language keyword, you need
to pass help it's name; if it's a function or a class, you can pass
help the object itself.
--
\S
under construction
Ever tried help("import") or help("if") or help("+") ?
help()-able in this context meaning you can drop the quotes and not
get a syntax error.