Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

why does "help(import)" not work?

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


rpjday at crashcourse

Nov 6, 2009, 1:56 AM

Post #1 of 16 (441 views)
Permalink
why does "help(import)" not work?

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
========================================================================
--
http://mail.python.org/mailman/listinfo/python-list


simon at brunningonline

Nov 6, 2009, 2:10 AM

Post #2 of 16 (430 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

2009/11/6 Robert P. J. Day <rpjday [at] crashcourse>:
>
>  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

import is a keyword, not an object.

--
Cheers,
Simon B.
--
http://mail.python.org/mailman/listinfo/python-list


deets at nospam

Nov 6, 2009, 2:11 AM

Post #3 of 16 (424 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

Robert P. J. Day schrieb:
> 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?

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
--
http://mail.python.org/mailman/listinfo/python-list


clp2 at rebertia

Nov 6, 2009, 2:12 AM

Post #4 of 16 (428 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day <rpjday [at] crashcourse> 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?

"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
--
http://mail.python.org/mailman/listinfo/python-list


bruno.42.desthuilliers at websiteburo

Nov 6, 2009, 2:12 AM

Post #5 of 16 (423 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

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
--
http://mail.python.org/mailman/listinfo/python-list


brian at sweetapp

Nov 6, 2009, 2:14 AM

Post #6 of 16 (429 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

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')

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
> =
> =
> ======================================================================
> --
> http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


rpjday at crashcourse

Nov 6, 2009, 2:28 AM

Post #7 of 16 (416 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

On Fri, 6 Nov 2009, Chris Rebert wrote:

> On Fri, Nov 6, 2009 at 1:56 AM, Robert P. J. Day <rpjday [at] crashcourse> 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
--

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

Linux Consulting, Training and Kernel Pedantry.

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


rpjday at crashcourse

Nov 6, 2009, 2:31 AM

Post #8 of 16 (423 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

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.

rday
--

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

Linux Consulting, Training and Kernel Pedantry.

Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
========================================================================
--
http://mail.python.org/mailman/listinfo/python-list


clp2 at rebertia

Nov 6, 2009, 2:36 AM

Post #9 of 16 (425 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

On Fri, Nov 6, 2009 at 2:28 AM, Robert P. J. Day <rpjday [at] crashcourse> 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> 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
--
http://mail.python.org/mailman/listinfo/python-list


rpjday at crashcourse

Nov 6, 2009, 2:36 AM

Post #10 of 16 (422 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

On Fri, 6 Nov 2009, Robert P. J. Day 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> 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.

rday
--

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

Linux Consulting, Training and Kernel Pedantry.

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


simon at brunningonline

Nov 6, 2009, 2:45 AM

Post #11 of 16 (424 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

2009/11/6 Robert P. J. Day <rpjday [at] crashcourse>:
>  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?

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.
--
http://mail.python.org/mailman/listinfo/python-list


simon at brunningonline

Nov 6, 2009, 2:47 AM

Post #12 of 16 (416 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

2009/11/6 Robert P. J. Day <rpjday [at] crashcourse>:
>  ah, ok, now it makes sense.  so python3 just lets me be sloppy about
> it, as in:

print is a function in Python 3, so that's fine. In Python 2, that
would also be a syntax error.

--
Cheers,
Simon B.
--
http://mail.python.org/mailman/listinfo/python-list


paul.nospam at rudin

Nov 6, 2009, 2:49 AM

Post #13 of 16 (424 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

"Robert P. J. Day" <rpjday [at] crashcourse> writes:

> 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.
--
http://mail.python.org/mailman/listinfo/python-list


sion at viridian

Nov 6, 2009, 2:51 AM

Post #14 of 16 (422 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

Robert P. J. Day <rpjday [at] crashcourse> wrote:
>On Fri, 6 Nov 2009, Brian Quinlan wrote:
>> 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)

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

--
http://mail.python.org/mailman/listinfo/python-list


bruno.42.desthuilliers at websiteburo

Nov 6, 2009, 7:15 AM

Post #15 of 16 (422 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

Chris Rebert a écrit :
> On Fri, Nov 6, 2009 at 2:28 AM, Robert P. J. Day <rpjday [at] crashcourse> wrote:
>
>> 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).

Ever tried help("import") or help("if") or help("+") ?

--
http://mail.python.org/mailman/listinfo/python-list


clp2 at rebertia

Nov 6, 2009, 10:04 AM

Post #16 of 16 (406 views)
Permalink
Re: why does "help(import)" not work? [In reply to]

On Fri, Nov 6, 2009 at 7:15 AM, Bruno Desthuilliers
<bruno.42.desthuilliers [at] websiteburo> wrote:
> Chris Rebert a écrit :
>> On Fri, Nov 6, 2009 at 2:28 AM, Robert P. J. Day <rpjday [at] crashcourse>
>> wrote:
>>>  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).
>
> 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.

Cheers,
Chris
--
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.