Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61357

Re: interactive help on the base object

From Terry Reedy <tjreedy@udel.edu>
Subject Re: interactive help on the base object
Date 2013-12-09 00:00 -0500
References <l7t00b$hp7$1@ger.gmane.org> <l7tu0b$s3o$1@ger.gmane.org> <mailman.3748.1386546562.18130.python-list@python.org> <l833rs$jik$1@dont-email.me> <l83787$q6$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.3759.1386565266.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/8/2013 8:43 PM, Mark Lawrence wrote:
> On 09/12/2013 00:45, Denis McMahon wrote:
>> On Sun, 08 Dec 2013 23:48:57 +0000, Mark Lawrence wrote:
>>
>>>>>   >>> help(object)
>>>>> Help on class object in module builtins:
>>>>>
>>>>> class object
>>>>>    |  The most base type
>>
>>
>>>> '''The default top superclass for all Python classes.
>>>> Its methods are inherited by all classes unless overriden.
>>>> '''

I said 'top' instead of 'bottom' or 'base' to loosen up thinking a bit. 
I did not expect Mark to make a mound out of that flip.

>>> Terry's suggestion above remains odds on favourite on the grounds that
>>> there have been no other suggestions.  I'll give it another day, then
>>> raise a tracker issue, unless the overwhelming smell of pot that has
>>> been drifting around this thread knocks me unconscious.
>>
>> """ The root class for all Python classes. Its methods are inherited by
>> all classes unless overriden. """

'Root' is even better, since it does not depend on whether a tree is 
drawn up or down. Thanks.

> Thanks Denis, you've reminded me why I asked in the first place.  What
> methods, if any does it provide?

Good question.
 >>> dir(object)
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', 
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', 
'__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', 
'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', 
'__subclasshook__']

>  Are they all abstract? etc???

No.

> Personally I'm not really interested, but a newbie might well be and
> hence might wonder what the hell is going on.

For everything else, help lists the special name methods directly 
associated with the object, along with docstrings.

 >>> help(C)
Help on class C in module __main__:

class C(builtins.object)
  |  Data descriptors defined here:
  |
  |  __dict__
  |      dictionary for instance variables (if defined)
  |
  |  __weakref__
  |      list of weak references to the object (if defined)

I think help should do the same for object

 >>> object.__hash__.__doc__
'x.__hash__() <==> hash(x)'

is equivalent to

  | __abs__(...)
  |      x.__abs__() <==> abs(x)

etc printed for help(int)

The fact that __dict__ does not exist for object but is only added for 
subclasses explains why one must subclass object to get instances that 
allow attributes.

 >>> o = object()
 >>> o.a = 1
Traceback (most recent call last):
   File "<pyshell#8>", line 1, in <module>
     o.a = 1
AttributeError: 'object' object has no attribute 'a'
 >>> c = C()
 >>> c.a=1

> If and only if the
> situation can be improved I'll raise an issue

I think it can be. If you prefer me to open the issue, say so.
We should look for existing issues, and closed issues that rejected change.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: interactive help on the base object Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-08 23:48 +0000
  Re: interactive help on the base object Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-09 00:45 +0000
    Re: interactive help on the base object Mark Janssen <dreamingforward@gmail.com> - 2013-12-08 17:09 -0800
    Re: interactive help on the base object Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-09 01:38 +0000
    Re: interactive help on the base object Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-09 01:43 +0000
      Re: interactive help on the base object Steven D'Aprano <steve@pearwood.info> - 2013-12-09 02:31 +0000
        Re: interactive help on the base object Mark Janssen <dreamingforward@gmail.com> - 2013-12-08 18:41 -0800
          Re: interactive help on the base object rusi <rustompmody@gmail.com> - 2013-12-08 18:58 -0800
            Re: interactive help on the base object Steven D'Aprano <steve@pearwood.info> - 2013-12-09 04:16 +0000
              Re: interactive help on the base object rusi <rustompmody@gmail.com> - 2013-12-08 20:46 -0800
                Re: interactive help on the base object rurpy@yahoo.com - 2013-12-08 21:26 -0800
                Re: interactive help on the base object rusi <rustompmody@gmail.com> - 2013-12-08 22:44 -0800
                Re: interactive help on the base object Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-09 09:44 +0000
          Re: interactive help on the base object Steven D'Aprano <steve@pearwood.info> - 2013-12-09 05:44 +0000
            Re: interactive help on the base object Alan Bawden <alan@scooby-doo.csail.mit.edu> - 2013-12-09 02:31 -0500
              Re: interactive help on the base object Chris Angelico <rosuav@gmail.com> - 2013-12-09 18:39 +1100
                Re: interactive help on the base object Alan Bawden <alan@scooby-doo.csail.mit.edu> - 2013-12-10 00:34 -0500
                Re: interactive help on the base object Chris Angelico <rosuav@gmail.com> - 2013-12-10 16:44 +1100
        Re: interactive help on the base object Chris Angelico <rosuav@gmail.com> - 2013-12-09 13:57 +1100
    Re: interactive help on the base object Terry Reedy <tjreedy@udel.edu> - 2013-12-09 00:00 -0500
    Re: interactive help on the base object Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-09 23:48 +0000
  Re: interactive help on the base object Steven D'Aprano <steve@pearwood.info> - 2013-12-09 01:58 +0000

csiph-web