Where is the help function defined?

P

Peng Yu

help(help) gives me the following explanation.

##################
Help on _Helper in module site object:

class _Helper(__builtin__.object)
| Define the built-in 'help'.
| This is a wrapper around pydoc.help (with a twist).
|
| Methods defined here:
|
| __call__(self, *args, **kwds)
|
| __repr__(self)
|
|
----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
###################

I then looked at pydoc site. But I don't see an entry on help(). How
to figure out where help() (or a function in general) is defined?
 
S

Stephen Hansen

Help on _Helper in module site object:

It says so right here.
I then looked at pydoc site. But I don't see an entry on help(). How
to figure out where help() (or a function in general) is defined?

Generally:

Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.<class 'site._Helper'>




--

Stephen Hansen
... Also: Ixokai
... Mail: me+list/python (AT) ixokai (DOT) io
... Blog: http://meh.ixokai.io/


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)

iQEcBAEBAgAGBQJMH6JxAAoJEKcbwptVWx/lfmcH/1z3vODQGEKKFxPU2WsIEMQr
4/BF99Wz7hUUUm1x6X2VghDKliKONtZxcGeRohf7gAfXhFSjU+GyJzN2Gj0ddZqe
HEQCUdFiMEOWHUrkWl1rJ94EmpTG8EvnLG5lzMFNaccny7BhPL0cdyFSewdBzIR5
RFIqv4QEqGBEAnrFXaG5ODdPcZtVTZyAk9BmMiyeVU3TwLKJDBU87eyT6Rl9Qwyk
Mgb1Fi5aSd/pgmul8S9O0z7nRD+NgwOszhDgAmOtlBIDqHRAWJlA6lzdH6NbpdMx
N5GA4Eno43BHQ1/wAZ87bpJ4S8xKSp4CLhFdb3AXEyR1Nme7gVCzmtrlOcw3rPw=
=MMkF
-----END PGP SIGNATURE-----
 
T

Thomas Jollans

help(help) gives me the following explanation.

[snip]

I then looked at pydoc site. But I don't see an entry on help(). How
to figure out where help() (or a function in general) is defined?


help is not a function, it's an instance of site._Helper. It just
"feels" like a function by being callable.
You could create your own "help" callable simply by using the _Helper
contructor:


-- Thomas
 
E

Emile van Sebille

On 6/21/2010 10:17 AM Peng Yu said...
help(help) gives me the following explanation.

I then looked at pydoc site. But I don't see an entry on help(). How
to figure out where help() (or a function in general) is defined?

ActivePython 2.4.1 Build 247 (ActiveState Corp.) based on
Python 2.4.1 (#65, Jun 20 2005, 17:01:55) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.['__call__', '__class__', '__delattr__', '__dict__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'__weakref__']['_Helper', '_Printer', '__builtin__', '__builtins__', '__doc__',
'__file__', '__name__', '_init_pathinfo', '_test', 'abs__file__',
'addbuilddir', 'addpackage', 'addsitedir', 'addsitepackages',
'aliasmbcs', 'execsitecustomize', 'main', 'makepath', 'os', 'removedup
paths', 'setBEGINLIBPATH', 'setcopyright', 'setencoding', 'sethelper',
'setquit', 'sys']

HTH,

Emile
 
T

Terry Reedy

help(help) gives me the following explanation.

##################
Help on _Helper in module site object:

class _Helper(__builtin__.object)
| Define the built-in 'help'.

See 'built-in'?

| This is a wrapper around pydoc.help (with a twist).
|
| Methods defined here:
|
| __call__(self, *args, **kwds)
|
| __repr__(self)
|
|
----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
###################

I then looked at pydoc site.

Which is?

Lib Ref 2. Built-in Functions has entry

help([object])
Invoke the built-in help system. (This function is intended for
interactive use.) If no argument is given, the interactive help system
starts on the interpreter console. If the argument is a string, then the
string is looked up as the name of a module, function, class, method,
keyword, or documentation topic, and a help page is printed on the
console. If the argument is any other kind of object, a help page on the
object is generated.

This function is added to the built-in namespace by the site module.

Peruse the first 6 chapers of the Library Reference so you are familiar
with what is there. I use them pretty regularly.

Terry Jan Reedy
 
T

Trent Mick

On 6/21/2010 10:17 AM Peng Yu said...
help(help) gives me the following explanation.

I then looked at pydoc site. But I don't see an entry on help(). How
to figure out where help() (or a function in general) is defined?

ActivePython 2.4.1 Build 247 (ActiveState Corp.) based on
Python 2.4.1 (#65, Jun 20 2005, 17:01:55) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.['__call__', '__class__', '__delattr__', '__dict__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'__weakref__']['_Helper', '_Printer', '__builtin__', '__builtins__', '__doc__',
'__file__', '__name__', '_init_pathinfo', '_test', 'abs__file__',
'addbuilddir', 'addpackage', 'addsitedir', 'addsitepackages',
'aliasmbcs', 'execsitecustomize', 'main', 'makepath', 'os', 'removedup
paths', 'setBEGINLIBPATH', 'setcopyright', 'setencoding', 'sethelper',
'setquit', 'sys']

"site.py" (at least in the Python trunk) has this:


def sethelper():
__builtin__.help = _Helper()



Trent
 

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,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top