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


Groups > comp.lang.python > #91576 > unrolled thread

Everything is an object in python - object class and type class

Started byEddilbert Macharia <edd.cowan@gmail.com>
First post2015-05-31 07:34 -0700
Last post2015-06-03 06:17 -0700
Articles 20 on this page of 100 — 20 participants

Back to article view | Back to comp.lang.python


Contents

  Everything is an object in python - object class and type class Eddilbert Macharia <edd.cowan@gmail.com> - 2015-05-31 07:34 -0700
    Re: Everything is an object in python - object class and type class Marco Buttu <marco.buttu@gmail.com> - 2015-05-31 17:13 +0200
    Re: Everything is an object in python - object class and type class Terry Reedy <tjreedy@udel.edu> - 2015-05-31 11:37 -0400
    Re: Everything is an object in python - object class and type class Steven D'Aprano <steve@pearwood.info> - 2015-06-01 04:00 +1000
      Re: Everything is an object in python - object class and type class "Dr. Bigcock" <dreamingforward@gmail.com> - 2015-06-01 10:35 -0700
    Re: Everything is an object in python - object class and type class Eddilbert Macharia <edd.cowan@gmail.com> - 2015-05-31 17:29 -0700
      Re: Everything is an object in python - object class and type class Steven D'Aprano <steve@pearwood.info> - 2015-06-01 14:09 +1000
    Re: Everything is an object in python - object class and type class Eddilbert Macharia <edd.cowan@gmail.com> - 2015-05-31 20:09 -0700
      Re: Everything is an object in python - object class and type class Steven D'Aprano <steve@pearwood.info> - 2015-06-01 14:24 +1000
    Re: Everything is an object in python - object class and type class Eddilbert Macharia <edd.cowan@gmail.com> - 2015-06-01 05:03 -0700
      Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-01 23:59 +0100
        Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-02 11:45 +0100
          Re: Everything is an object in python - object class and type class Rustom Mody <rustompmody@gmail.com> - 2015-06-02 04:16 -0700
        Re: Everything is an object in python - object class and type class Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-02 09:09 -0600
      Re: Everything is an object in python - object class and type class TheDoctor <dreamingforward@gmail.com> - 2015-06-01 17:24 -0700
        Re: Everything is an object in python - object class and type class Chris Angelico <rosuav@gmail.com> - 2015-06-02 10:32 +1000
          Re: Everything is an object in python - object class and type class TheDoctor <dreamingforward@gmail.com> - 2015-06-01 18:02 -0700
            Re: Everything is an object in python - object class and type class Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-02 16:30 +1000
          Re: Everything is an object in python - object class and type class TheDoctor <dreamingforward@gmail.com> - 2015-06-01 18:15 -0700
            Re: Everything is an object in python - object class and type class Chris Angelico <rosuav@gmail.com> - 2015-06-02 11:30 +1000
            Re: Everything is an object in python - object class and type class random832@fastmail.us - 2015-06-02 00:13 -0400
            Re: Everything is an object in python - object class and type class Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-02 16:23 +1000
        Re: Everything is an object in python - object class and type class Rustom Mody <rustompmody@gmail.com> - 2015-06-01 20:15 -0700
          Re: Everything is an object in python - object class and type class Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-02 04:46 +0100
          Re: Everything is an object in python - object class and type class TheDoctor <dreamingforward@gmail.com> - 2015-06-01 21:47 -0700
            Re: Everything is an object in python - object class and type class Rustom Mody <rustompmody@gmail.com> - 2015-06-01 22:01 -0700
              Religion [was Re: Everything is an object in python - object class and type class] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-02 16:04 +1000
                Re: Religion [was Re: Everything is an object in python - object class and type class] Rustom Mody <rustompmody@gmail.com> - 2015-06-01 23:17 -0700
                Re: Religion [was Re: Everything is an object in python - object class and type class] Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-02 07:20 +0100
        Re: Everything is an object in python - object class and type class random832@fastmail.us - 2015-06-02 00:08 -0400
          Re: Everything is an object in python - object class and type class TheDoctor <dreamingforward@gmail.com> - 2015-06-01 21:54 -0700
        Re: Everything is an object in python - object class and type class Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-02 17:12 +1000
          Re: Everything is an object in python - object class and type class Rustom Mody <rustompmody@gmail.com> - 2015-06-02 00:44 -0700
            Re: Everything is an object in python - object class and type class Chris Angelico <rosuav@gmail.com> - 2015-06-02 18:37 +1000
              Re: Everything is an object in python - object class and type class Rustom Mody <rustompmody@gmail.com> - 2015-06-02 02:18 -0700
              Re: Everything is an object in python - object class and type class Marko Rauhamaa <marko@pacujo.net> - 2015-06-02 12:23 +0300
    Re: Everything is an object in python - object class and type class vern.muhr@gmail.com - 2015-06-01 14:12 -0700
    Re: Everything is an object in python - object class and type class Eddilbert Macharia <edd.cowan@gmail.com> - 2015-06-02 03:36 -0700
      Re: Everything is an object in python - object class and type class Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-02 12:11 +0100
      Re: Everything is an object in python - object class and type class Steven D'Aprano <steve@pearwood.info> - 2015-06-02 21:27 +1000
        Re: Everything is an object in python - object class and type class Rustom Mody <rustompmody@gmail.com> - 2015-06-02 04:40 -0700
          Re: Everything is an object in python - object class and type class Steven D'Aprano <steve@pearwood.info> - 2015-06-03 01:08 +1000
            Re: Everything is an object in python - object class and type class Rustom Mody <rustompmody@gmail.com> - 2015-06-02 09:14 -0700
        Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-02 13:49 +0100
          Re: Everything is an object in python - object class and type class Marko Rauhamaa <marko@pacujo.net> - 2015-06-02 16:13 +0300
          Re: Everything is an object in python - object class and type class Steven D'Aprano <steve@pearwood.info> - 2015-06-03 03:00 +1000
            Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-02 18:59 +0100
              Re: Everything is an object in python - object class and type class random832@fastmail.us - 2015-06-02 14:07 -0400
              Re: Everything is an object in python - object class and type class Ned Batchelder <ned@nedbatchelder.com> - 2015-06-02 11:10 -0700
                Re: Everything is an object in python - object class and type class Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-02 13:36 -0600
              Re: Everything is an object in python - object class and type class Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-06-02 18:10 +0000
              Re: Everything is an object in python - object class and type class "Dr. Bigcock" <dreamingforward@gmail.com> - 2015-06-02 11:22 -0700
                Re: Everything is an object in python - object class and type class Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-06-02 18:47 +0000
                  Re: Everything is an object in python - object class and type class "Dr. Bigcock" <dreamingforward@gmail.com> - 2015-06-02 12:00 -0700
                    Re: Everything is an object in python - object class and type class Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-06-02 19:31 +0000
                      Re: Everything is an object in python - object class and type class Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-02 13:50 -0600
                        Re: Everything is an object in python - object class and type class Grant Edwards <invalid@invalid.invalid> - 2015-06-02 21:19 +0000
                          Re: Everything is an object in python - object class and type class Marko Rauhamaa <marko@pacujo.net> - 2015-06-03 01:33 +0300
                            Re: Everything is an object in python - object class and type class "Dr. Bigcock" <dreamingforward@gmail.com> - 2015-06-02 15:49 -0700
                              Re: Everything is an object in python - object class and type class Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-03 18:13 +1000
                                Re: Everything is an object in python - object class and type class "Dr. Bigcock" <dreamingforward@gmail.com> - 2015-06-03 21:38 -0700
                            Re: Everything is an object in python - object class and type class Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-03 18:24 +1000
                              Re: Everything is an object in python - object class and type class Marko Rauhamaa <marko@pacujo.net> - 2015-06-03 11:57 +0300
                                Re: Everything is an object in python - object class and type class Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-03 07:57 -0600
                                Re: Everything is an object in python - object class and type class "Dr. Bigcock" <dreamingforward@gmail.com> - 2015-06-03 21:42 -0700
                      Re: Everything is an object in python - object class and type class "Dr. Bigcock" <dreamingforward@gmail.com> - 2015-06-02 12:58 -0700
                      Re: Everything is an object in python - object class and type class Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-02 22:47 +0100
                      Re: Everything is an object in python - object class and type class Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-02 18:49 -0600
                      Re: Everything is an object in python - object class and type class Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-03 18:32 +1000
                  Re: Everything is an object in python - object class and type class Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-02 13:37 -0600
              Re: Everything is an object in python - object class and type class Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-03 18:08 +1000
            Re: Everything is an object in python - object class and type class "Dr. Bigcock" <dreamingforward@gmail.com> - 2015-06-02 11:00 -0700
        Re: Everything is an object in python - object class and type class Eddilbert Macharia <edd.cowan@gmail.com> - 2015-06-02 21:16 -0700
          Re: Everything is an object in python - object class and type class Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-03 06:23 +0100
          Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-03 11:20 +0100
            Re: Everything is an object in python - object class and type class Chris Angelico <rosuav@gmail.com> - 2015-06-03 20:38 +1000
              Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-03 12:08 +0100
                Re: Everything is an object in python - object class and type class Marko Rauhamaa <marko@pacujo.net> - 2015-06-03 15:08 +0300
                  Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-03 17:00 +0100
                    Re: Everything is an object in python - object class and type class Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-03 17:29 +0100
                      Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-03 19:59 +0100
                        Re: Everything is an object in python - object class and type class Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-03 21:58 +0100
                          Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-03 22:33 +0100
                            Re: Everything is an object in python - object class and type class Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-03 22:49 +0100
                              Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-04 00:04 +0100
                                Re: Everything is an object in python - object class and type class Laura Creighton <lac@openend.se> - 2015-06-04 12:06 +0200
                                  Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-04 13:01 +0100
                                    Re: Everything is an object in python - object class and type class Laura Creighton <lac@openend.se> - 2015-06-04 15:39 +0200
                          Re: Everything is an object in python - object class and type class "Dr. Bigcock" <dreamingforward@gmail.com> - 2015-06-03 21:50 -0700
                            Re: Everything is an object in python - object class and type class Eddilbert Macharia <edd.cowan@gmail.com> - 2015-06-03 22:43 -0700
                    Re: Everything is an object in python - object class and type class Michael Torrie <torriem@gmail.com> - 2015-06-03 10:36 -0600
                      Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-03 18:26 +0100
                        Re: Everything is an object in python - object class and type class Steven D'Aprano <steve@pearwood.info> - 2015-06-05 00:11 +1000
                    Re: Everything is an object in python - object class and type class Terry Reedy <tjreedy@udel.edu> - 2015-06-03 13:17 -0400
                Re: Everything is an object in python - object class and type class Chris Angelico <rosuav@gmail.com> - 2015-06-03 22:19 +1000
                Re: Everything is an object in python - object class and type class Marco Buttu <marco.buttu@gmail.com> - 2015-06-03 14:10 +0200
            Re: Everything is an object in python - object class and type class BartC <bc@freeuk.com> - 2015-06-03 12:13 +0100
            Re: Everything is an object in python - object class and type class Terry Reedy <tjreedy@udel.edu> - 2015-06-03 13:05 -0400
      Re: Everything is an object in python - object class and type class Terry Reedy <tjreedy@udel.edu> - 2015-06-02 12:23 -0400
    Re: Everything is an object in python - object class and type class Eddilbert Macharia <edd.cowan@gmail.com> - 2015-06-03 06:17 -0700

Page 1 of 5  [1] 2 3 4 5  Next page →


#91576 — Everything is an object in python - object class and type class

FromEddilbert Macharia <edd.cowan@gmail.com>
Date2015-05-31 07:34 -0700
SubjectEverything is an object in python - object class and type class
Message-ID<14976c1b-a620-426f-b529-41a3c04e9c1a@googlegroups.com>
Hello All ,

I'm wrecking my head trying to understand. where the class object comes into play . 

Is it only meant to act as base class and does it mean there is an actual class called object in python which all the objects created using the class type inherit ?

i'm assuming the metaclass if simplified would look something like this :

type('dict', (object,),{})

And when we use the class type as a metaclass are we using the instance version of the class type or are we actually using the type class itself ?

Also when we say everything is an object in python, are we referring to the fact that everything is an instance of the class type or does it have to with the object class inherited ? 

As can be attested by using type() function as below :

>>> type(int)
<class 'type'>
>>> type(list)
<class 'type'>
>>> type(dict)
<class 'type'>
>>> type(type)
<class 'type'>
>>> type(object)
<class 'type'>

From my understanding this means all of this are instances of the class type. which means the class type was used to create this instances.

Now if i look at the __bases__ of all this objects i get :

>>> type.__base__
<class 'object'>
>>> type.__bases__
(<class 'object'>,)
>>> dict.__bases__
(<class 'object'>,)
>>> list.__bases__
(<class 'object'>,)
>>> int.__bases__
(<class 'object'>,)
>>> object.__bases__
()

This tells me that all of this objects inherit from the class object which has nothing to do with them being instances.

[toc] | [next] | [standalone]


#91581

FromMarco Buttu <marco.buttu@gmail.com>
Date2015-05-31 17:13 +0200
Message-ID<mailman.249.1433085311.5151.python-list@python.org>
In reply to#91576
On 31/05/2015 16:34, Eddilbert Macharia wrote:

> Also when we say everything is an object in python, are we referring to the fact that everything is an instance of the class type or does it have to with the object class inherited ?

 From Wikipedia: "In the class-based object-oriented programming 
paradigm, `object` refers to a particular instance of a class"

So, because in Python everything is an instance of the class object 
(isinstance(obj, object) is always True), everything is an object.
Only classes are instance of type. That means is worth to differentiate 
between classes and non-classes, but it is a non-sense to differentiate 
between classes and objects. If it could be useful:

http://marco-buttu.github.io/pycon_objmodel/

> As can be attested by using type() function as below :
>
>>>> >>>type(int)
> <class 'type'>
>>>> >>>type(list)
...
> >From my understanding this means all of this are instances of the 
> class type. which means the class type was used to create this instances. 

Yes, that is true, because all these objects are classes

> Now if i look at the __bases__ of all this objects i get :
>>>> >>>type.__base__
> <class 'object'>
>>>> >>>type.__bases__
> (<class 'object'>,)
> ...

> This tells me that all of this objects inherit from the class object which has nothing to do with them being instances.

Take a look at all the steps that anticipate this diagram:

http://marco-buttu.github.io/pycon_objmodel/?full#Diagram

Every class inherits from object, and that implies every instance of a 
class is an instance of object. And classes are instance of a class 
(thier metaclass), so they are instance of objects too

-- 
Marco Buttu

INAF-Osservatorio Astronomico di Cagliari
Via della Scienza n. 5, 09047 Selargius (CA)
Phone: 070 711 80 217
Email: mbuttu@oa-cagliari.inaf.it

[toc] | [prev] | [next] | [standalone]


#91582

FromTerry Reedy <tjreedy@udel.edu>
Date2015-05-31 11:37 -0400
Message-ID<mailman.250.1433086663.5151.python-list@python.org>
In reply to#91576
On 5/31/2015 10:34 AM, Eddilbert Macharia wrote:

> I'm wrecking my head trying to understand. where the class object comes into play .

Leaving custom metaclasses aside.

1. All python data values are instances of some class.

2. Every class is a instance of the metaclass 'type'.

3. Every class is a subclass of the base class 'object'.

Some implications.

4. All objects, including classes, get their basic instance behaviors 
from 'object', except as over-riden by other classes in the inheritance 
chain.  These basic behaviors include default comparisons and 
representations.  See 'dir(object)'.

5. Classes get their special class behaviors from 'type'.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#91586

FromSteven D'Aprano <steve@pearwood.info>
Date2015-06-01 04:00 +1000
Message-ID<556b4c52$0$13013$c3e8da3$5496439d@news.astraweb.com>
In reply to#91576
On Mon, 1 Jun 2015 12:34 am, Eddilbert Macharia wrote:

> Hello All ,
> 
> I'm wrecking my head trying to understand. where the class object comes
> into play .

This is just the standard object-oriented concept of class and instances.
Have you programmed in any other OO language? 

Lassie is an individual example of a dog. Lassie is an instance, dog is the
class.

42 is an individual example of an int (integer). 42 is an instance, int is
the class (also known as type).

In some languages, like Java, and Javascript, there are two "kinds" of
values: objects, and primitives. Primitives are the sorts of values you use
in low-level languages like C, Fortran or Pascal, or in assembly language:
typically things like numbers, arrays, strings, booleans (True and False).
These are sometimes called "unboxed" values, "boxed" values being another
name for objects.

Python is not like those languages -- all values in Python are objects, in
the sense of object-oriented programming.



> Is it only meant to act as base class and does it mean there is an actual
> class called object in python which all the objects created using the
> class type inherit ?

Yes, there is an actual class called "object" in Python:

py> object
<class 'object'>

In Python 3, all values are objects in BOTH the sense of OO programming, and
the sense that the inherit from the object class.

In Python 2, for historical reasons, *some* classes do not inherit from
object, but form a separate hierarchy called "classic" or "old-style"
classes. It's best to ignore them, if you can, since they add complexity
for little value. I will say no more about these classic classes, although
if you are really curious, ask and someone (possibly me) will answer.


> i'm assuming the metaclass if simplified would look something like this :
> 
> type('dict', (object,),{})
> 
> And when we use the class type as a metaclass are we using the instance
> version of the class type or are we actually using the type class itself ?

I don't understand what you are trying to ask.


Every instance belongs to a class: 42 is an instance of int, "spam and eggs"
is an instance of str. In Python, classes themselves are also values, and
hence are instances of some other class. This class-of-the-class is called
the metaclass.

int is a class, int is an instance of the metaclass called "type";
str is a class, str is an instance of the metaclass called "type";

etc. Normally, all the classes you come across will belong to the same
metaclass, type.

Since type itself is a class, what's its metaclass? (The "metametaclass",
you might say, although we never do :-) Well, type is special. The chain of
instance <- class <- metaclass <- metametaclass <- ... cannot go on
forever, and so the Python interpreter treats type as special, so that the
chain of meta-meta-meta-meta...classes has a beginning:

type -> int -> 42

The class of type is itself!

py> type(type) is type
True

So, when you create your own class:

class Spam(object):
    def method(self):
        return "spam spam spam"


Python treats this as syntactic sugar for a call to type:

Spam = type("Spam", (object,), {'method': function-object})


That's right, type() does two things! With a single argument, it returns the
type (class) of the value passed in:

py> type(42)
<class 'int'>


With three arguments, it creates a new class.

So if you use a metaclass, Python simply replaces the call to type(...) with
a call to the metaclass.

Typically, you won't use metaclasses *at all*, but for those rare times when
you do, the usual pattern is:

- create a subclass of type that does something different;
- specify that as the metaclass.


class Meta(type):
    ...


# Python 3 syntax
class MyClass(object, metaclass=Meta):
    ...

# Python 2 syntax
class MyClass(object):
    __metaclass__ = Meta
    ...


Then, instead of the MyClass class definition being syntactic sugar for:


MyClass = type("MyClass", (object,), {...})  # the default

it becomes:

MyClass = Meta("MyClass", (object,), {...})

So now MyClass is an instance of Meta, which is a subclass of type.


That's (almost!) all there is to it. I've actually simplified a few of the
hairier details and ignored some of the complexity, but as a broad
overview, this is about everything you need to know about metaclasses.



> Also when we say everything is an object in python, are we referring to
> the fact that everything is an instance of the class type or does it have
> to with the object class inherited ?

Yes to both of those!



> As can be attested by using type() function as below :
[...] 
> From my understanding this means all of this are instances of the class
> type. which means the class type was used to create this instances.

Correct.


> Now if i look at the __bases__ of all this objects i get :
> 
>>>> type.__base__
> <class 'object'>
>>>> type.__bases__
> (<class 'object'>,)
>>>> dict.__bases__
> (<class 'object'>,)
>>>> list.__bases__
> (<class 'object'>,)
>>>> int.__bases__
> (<class 'object'>,)
>>>> object.__bases__
> ()
> 
> This tells me that all of this objects inherit from the class object which
> has nothing to do with them being instances.

Also correct.




-- 
Steven

[toc] | [prev] | [next] | [standalone]


#91700

From"Dr. Bigcock" <dreamingforward@gmail.com>
Date2015-06-01 10:35 -0700
Message-ID<5414e38c-ad39-4e5d-ad79-1c767e72cc3d@googlegroups.com>
In reply to#91586
On Sunday, May 31, 2015 at 1:01:03 PM UTC-5, Steven D'Aprano wrote:
> On Mon, 1 Jun 2015 12:34 am, Eddilbert Macharia wrote:
> 
> > Hello All ,
> > 
> > I'm wrecking my head trying to understand. where the class object comes
> > into play .
> 
> This is just the standard object-oriented concept of class and instances.
> Have you programmed in any other OO language? 

The issue here is:  which one is the object?  The class or the instance?

;^),

-m

[toc] | [prev] | [next] | [standalone]


#91600

FromEddilbert Macharia <edd.cowan@gmail.com>
Date2015-05-31 17:29 -0700
Message-ID<9ad6e2be-b3bf-4676-b486-82eab504fe64@googlegroups.com>
In reply to#91576
So what im getting from above reponse, everything in python is an object because the are instance of the metaclass type and also because they are subclasses of the class object ?


On Sunday, May 31, 2015 at 5:34:20 PM UTC+3, Eddilbert Macharia wrote:
> Hello All ,
> 
> I'm wrecking my head trying to understand. where the class object comes into play . 
> 
> Is it only meant to act as base class and does it mean there is an actual class called object in python which all the objects created using the class type inherit ?
> 
> i'm assuming the metaclass if simplified would look something like this :
> 
> type('dict', (object,),{})
> 
> And when we use the class type as a metaclass are we using the instance version of the class type or are we actually using the type class itself ?
> 
> Also when we say everything is an object in python, are we referring to the fact that everything is an instance of the class type or does it have to with the object class inherited ? 
> 
> As can be attested by using type() function as below :
> 
> >>> type(int)
> <class 'type'>
> >>> type(list)
> <class 'type'>
> >>> type(dict)
> <class 'type'>
> >>> type(type)
> <class 'type'>
> >>> type(object)
> <class 'type'>
> 
> From my understanding this means all of this are instances of the class type. which means the class type was used to create this instances.
> 
> Now if i look at the __bases__ of all this objects i get :
> 
> >>> type.__base__
> <class 'object'>
> >>> type.__bases__
> (<class 'object'>,)
> >>> dict.__bases__
> (<class 'object'>,)
> >>> list.__bases__
> (<class 'object'>,)
> >>> int.__bases__
> (<class 'object'>,)
> >>> object.__bases__
> ()
> 
> This tells me that all of this objects inherit from the class object which has nothing to do with them being instances.

[toc] | [prev] | [next] | [standalone]


#91611

FromSteven D'Aprano <steve@pearwood.info>
Date2015-06-01 14:09 +1000
Message-ID<556bdae7$0$12977$c3e8da3$5496439d@news.astraweb.com>
In reply to#91600
On Mon, 1 Jun 2015 10:29 am, Eddilbert Macharia wrote:

> 
> So what im getting from above reponse, everything in python is an object
> because the are instance of the metaclass type and also because they are
> subclasses of the class object ?

No.

Everything in Python is an object because Python has no "primitive"
or "unboxed" types, no machine values. This has nothing to do with
metaclasses. Even if Python had no metaclasses, it could still be true
that "everything is an object".

To summarise:

(1) In Python, "everything is an object" (that is, all values are objects)
is because Python does not include any primitive unboxed values. Anything
which can be used as a value (int, str, float, functions, modules, etc) are
implemented as objects.

(2) Python *also* has metaclasses. This does not follow from the above --
they are independent statements about the language. We could, if we want,
invent new languages:

- one where everything is an object, just like Python, but lacking
metaclasses;

- one which has metaclasses, just like Python, but not everything is an
object;

- and one which *neither* has metaclasses, *nor* everything is an object.

(Java is an example of the third one -- it has something kinda-sorta like
metaclasses, but it's just a tool for reflection, not the real thing.)


If that's enough, you can stop reading. But if you want more detail:


We can characterise various kinds of things in a programming language:

(1) Simple machine types, like bytes, integers, floats. These have no
internal structure, apart from individual bits. These are sometimes
called "machine primitives", and are the sorts of things you work with in
assembly language.

(2) Compound or structured machine types. These are made up of one or more
simple machine type, and include things like C structs and arrays.

(3) Objects, which are a more complex kind of compound type. More
importantly, objects involve a way of thinking about programming: some form
of inheritance, for example. Physically, an object is just a struct. But
it's a struct with a specific kind of meaning to the programming language,
which allows the language to provide inheritance, runtime types, and
various other goodies involved in Object Oriented Programming.

A language can choose to allow any or these, or all of these:

- assembly languages typically only support the most primitive, simple
machine types;

- languages like C and Pascal supports only simple and compound machine
types;

- some languages include both simple machine primitives and objects, such as
Java and Javascript;

- other languages don't offer any direct access to machine primitives, so
all values are objects, for example Python and Ruby.


To give a concrete example, consider a language with an "integer" type. In
C, an integer will be a machine primitive, a single, unstructured chunk of
memory with typically 32 bits, and that's all there is to it. In Python, an
integer will be an object, a large block of *structured* memory, typically
over 100 bits long, and different parts of that structure are used
internally to the interpreter.

A separate issue is whether or not classes are values. In some languages,
classes are *not* values: you cannot pass a class as argument to a
function, or assign it to a variable. In languages like these, classes are
not things (values), so "everything is an object" remains true even though
classes are not objects. Java is an example of that.

In Python, classes *are* variables. So we could have:

"In Python, everything is an object, or a class";

or

"In Python, everything is an object, including classes".


Which is true? The second is true: classes themselves are objects.

Finally, we have one last feature: does the language provide metaclasses?
Python does. Ruby, which is otherwise very similar to Python, does not:

In Python, everything is an object, and we have metaclasses.

In Ruby, everything is an object, but we don't have metaclasses.

http://ruby.dzone.com/news/ruby-doesnt-have-meta-classes



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#91608

FromEddilbert Macharia <edd.cowan@gmail.com>
Date2015-05-31 20:09 -0700
Message-ID<c5d52ef0-e5fc-48b6-a30c-846772ff9618@googlegroups.com>
In reply to#91576
Thank you for you responses guys.

So what I'm getting from above responses, everything in python is an object because the are instance of the metaclass type (from Steven response) and also because they are subclasses of the class object (from Marco and Terry response)? 
I'm having headache trying to understand the cyclic relationship that exit between the metaclass type, the object class, and the class type.

I'm trying to understand how python makes everything an object.is it because everything is an instance of the metaclass type or is it because everything is a subclass of object class.

if its because of being subclass of object class, does that mean if the class object was named class pyobj. would that make everything python pyobj ?

i know objects created by metaclass are types/classes, this types are then used to create other object.

From this :  
`>>> isinstance(type, object)
True`  
`>>> isinstance(object,type)
True`  
`>>> issubclass(object,type)
False`  
`>>> issubclass(type,object)
True`  

Is it safe to say that python creates the class object first using the type metaclass (I'm simplifying the metaclass for brevity).

`type('object',(),{})`  

which implies class object is a class of class type and it does not inherit any attributes other class.

Then it creates the class type 

`type('type', (object,),{})`  

implying type class is class of class type and it inherits attributes from the object class.

Then creates the other classes by inheriting from the class object

`type('dict', (object,), {})`  
`type('Animal', (object), {})`

which similar to creating an Animal class as :
    
    `class Animal:
         pass`

Does this mean the metaclass used to create the class object is still the one used to create this Animal class or is the metaclass type used by default ? 

Which type is being used, is it the metaclass type or the type class that was created after object was created ? 

Where does the class type created with the base class object come into play ?

I have also tried to understand what really is going on between the object and the class from all he responses above and in this article http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html

But i'm still getting confused.What is the relation between this two class in terms of object creation.

will i ever get this or is it a chicken and egg situation ?




On Sunday, May 31, 2015 at 5:34:20 PM UTC+3, Eddilbert Macharia wrote:
> Hello All ,
> 
> I'm wrecking my head trying to understand. where the class object comes into play . 
> 
> Is it only meant to act as base class and does it mean there is an actual class called object in python which all the objects created using the class type inherit ?
> 
> i'm assuming the metaclass if simplified would look something like this :
> 
> type('dict', (object,),{})
> 
> And when we use the class type as a metaclass are we using the instance version of the class type or are we actually using the type class itself ?
> 
> Also when we say everything is an object in python, are we referring to the fact that everything is an instance of the class type or does it have to with the object class inherited ? 
> 
> As can be attested by using type() function as below :
> 
> >>> type(int)
> <class 'type'>
> >>> type(list)
> <class 'type'>
> >>> type(dict)
> <class 'type'>
> >>> type(type)
> <class 'type'>
> >>> type(object)
> <class 'type'>
> 
> From my understanding this means all of this are instances of the class type. which means the class type was used to create this instances.
> 
> Now if i look at the __bases__ of all this objects i get :
> 
> >>> type.__base__
> <class 'object'>
> >>> type.__bases__
> (<class 'object'>,)
> >>> dict.__bases__
> (<class 'object'>,)
> >>> list.__bases__
> (<class 'object'>,)
> >>> int.__bases__
> (<class 'object'>,)
> >>> object.__bases__
> ()
> 
> This tells me that all of this objects inherit from the class object which has nothing to do with them being instances.

[toc] | [prev] | [next] | [standalone]


#91613

FromSteven D'Aprano <steve@pearwood.info>
Date2015-06-01 14:24 +1000
Message-ID<556bde79$0$12982$c3e8da3$5496439d@news.astraweb.com>
In reply to#91608
On Mon, 1 Jun 2015 01:09 pm, Eddilbert Macharia wrote:

> Thank you for you responses guys.
> 
> So what I'm getting from above responses, everything in python is an
> object because the are instance of the metaclass type (from Steven
> response) and also because they are subclasses of the class object (from
> Marco and Terry response)? I'm having headache trying to understand the
> cyclic relationship that exit between the metaclass type, the object
> class, and the class type.
> 
> I'm trying to understand how python makes everything an object.is it
> because everything is an instance of the metaclass type or is it because
> everything is a subclass of object class.

Neither. You have the relationship confused.

Everything is an *instance* of the *class*, not the metaclass:

py> isinstance(42, type)  # type is the metaclass
False
py> isinstance(42, int)  # int is the class of 42
True


Most things are *not* subclasses of object:

py> issubclass(42, object)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: issubclass() arg 1 must be a class



> if its because of being subclass of object class, does that mean if the
> class object was named class pyobj. would that make everything python
> pyobj ?

No. "Object" is a standard term from computer science, Python could
rename "object" to "wibble", and we would still say "everything is an
object.

There are *two* (actually three) common meanings for the word "object" in
Python programming:

- the general meaning of object, as in Object Oriented Programming, shared
with hundreds of other languages;

- the specific, Python meaning, as in the built-in class called "object";

- and more rarely, as a synonym for "instance", as opposed to "class".


"Everything is an object" is understood in terms of Object Oriented
Programming. It was true way back in Python version 1.5, before the
built-in "object" class existed. It would still be true even if the
built-in "object" class was renamed to "wibble".

This:

py> isinstance(23, object)
True

is true because "object" is also the base class for everything in Python.
But that's a separate meaning.



[...]
> Is it safe to say that python creates the class object first using the
> type metaclass (I'm simplifying the metaclass for brevity).

No. type and object are special, and have to be bootstrapped into existence
by the interpreter. You cannot create type first, because type is an
object, so object needs to exist first. But you cannot create object first,
because object is a type, and so type has to exist.

You cannot solve this problem by creating one first, then the other. The
interpreter has to create them both.

[..]
> will i ever get this or is it a chicken and egg situation ?

Yes, exactly. You cannot break the cycle from Python code, it has to be done
deep inside the interpreter.




-- 
Steven

[toc] | [prev] | [next] | [standalone]


#91659

FromEddilbert Macharia <edd.cowan@gmail.com>
Date2015-06-01 05:03 -0700
Message-ID<7f287dcf-8d52-4ab8-9768-88d1f75da269@googlegroups.com>
In reply to#91576
Thank you all who have taken there time to assist me.
Special thanks to Steven D'Aparo even though you didn't have two you have taken you time to go into details.

I think i kind of understand now. 

Instead of python having data types like int, string, e.t.c it has two primitive types which are class type and class object which are created by python interpreter during its setup .using this two classes python is able to create some more data types

In some context type means the data type an object is e.g. an int,string e.t.c.

In the new class style, type and class sort of mean the same thing.

**type type is used to create new types when used as a metaclass 
**type object is used to provide some default behavior and attributes to this types through inheritance

The interpreter makes sure of the following 

** The type type inherits from data type object which makes the following statements are true

>>> issubclass(type,object)
True # type inherits object as its parent

>>> isinstance(type,object) 
True # because of the inheritance 

>>> type.__bases__ 
(<class 'object'>,) # because of the inheritance 

>>> isinstance(type,type) 
True # because metaclass type was used to create this data type type

** The type object is created using the type type i.e. type object is an instance of type type. The type object does not subclass i.e. inherit from any other types. 

>>> isinstance(object,type) 
True # because metaclass type was used to create this object

>>> issubclass(object,type)
False # because object does not inherit from any other class

>>> object.__bases__
() # because object does not inherit from any other class



On Sunday, May 31, 2015 at 5:34:20 PM UTC+3, Eddilbert Macharia wrote:
> Hello All ,
> 
> I'm wrecking my head trying to understand. where the class object comes into play . 
> 
> Is it only meant to act as base class and does it mean there is an actual class called object in python which all the objects created using the class type inherit ?
> 
> i'm assuming the metaclass if simplified would look something like this :
> 
> type('dict', (object,),{})
> 
> And when we use the class type as a metaclass are we using the instance version of the class type or are we actually using the type class itself ?
> 
> Also when we say everything is an object in python, are we referring to the fact that everything is an instance of the class type or does it have to with the object class inherited ? 
> 
> As can be attested by using type() function as below :
> 
> >>> type(int)
> <class 'type'>
> >>> type(list)
> <class 'type'>
> >>> type(dict)
> <class 'type'>
> >>> type(type)
> <class 'type'>
> >>> type(object)
> <class 'type'>
> 
> From my understanding this means all of this are instances of the class type. which means the class type was used to create this instances.
> 
> Now if i look at the __bases__ of all this objects i get :
> 
> >>> type.__base__
> <class 'object'>
> >>> type.__bases__
> (<class 'object'>,)
> >>> dict.__bases__
> (<class 'object'>,)
> >>> list.__bases__
> (<class 'object'>,)
> >>> int.__bases__
> (<class 'object'>,)
> >>> object.__bases__
> ()
> 
> This tells me that all of this objects inherit from the class object which has nothing to do with them being instances.

[toc] | [prev] | [next] | [standalone]


#91730

FromBartC <bc@freeuk.com>
Date2015-06-01 23:59 +0100
Message-ID<3t5bx.755107$dj1.564752@fx03.am4>
In reply to#91659
On 01/06/2015 13:03, Eddilbert Macharia wrote:
> Thank you all who have taken there time to assist me.
> Special thanks to Steven D'Aparo even though you didn't have two you have taken you time to go into details.
>
> I think i kind of understand now.
>
> Instead of python having data types like int, string, e.t.c it has two primitive types which are class type and class object which are created by python interpreter during its setup .using this two classes python is able to create some more data types
>
> In some context type means the data type an object is e.g. an int,string e.t.c.
>
> In the new class style, type and class sort of mean the same thing.

I'm developing a new language along the lines of Python, perhaps a brief 
description of how things are done there might help. Or just give a 
different perspective.

Objects in this language are tagged: there's a code attached to each 
indicating what kind of data is stored. These codes are integers, or 
enumerations, for example:

  Int =    1
  String = 2
  List =   3
  Class =  4

And the following are examples of object instances with their tags:

a is (Int,    42)
b is (String, "ABCXYZ")
c is (List,   [10,20,30,40])
d is (Class,  2 or <String>)

The last one might be tricky to grasp: it's really just a number, but 
one that represents a class or type (or tag). If printed, it could 
display <String> rather than just 2. (And when used to do something with 
the class, the 2 might be an index into a set of tables.)

d is not /the/ class itself, but just a reference to it (this is 
pseudo-code not Python):

print (b)                 =>  ABCXYZ
print (typeof(b))         =>  String <2>

print (d)                 =>  String <2>
print (typeof(d))         =>  Class  <4>
print (typeof(typeof(d))) =>  Class  <4>

In my own language, the connection between class and type is hazy (I've 
only just added classes so it needs to be hazy until I understand them 
more).

'Type' includes everything, including all the built-in types such as the 
tags above, but also user-defined classes. In fact classes are the 
mechanism used to define new types. But with both designated by an 
integer within the same band (eg. built-int types 1 to 20, user-defined 
classes 21 and up), it is easier not to have a strong distinction ... at 
the moment.

I haven't a root class yet that is the base of all the others. I don't 
think it's necessary internally to make things work. But it might be a 
useful concept in the language. Calling it 'object' however might give 
rise to confusion as 'object' is informally used to refer to instances. 
(I've never used OO but have picked up some of the jargon!)

(This is almost certainly not how Python does things. Although the 
Python language doesn't go into details as to its implementation 
provided the behaviour is correct.)

-- 
Bartc

[toc] | [prev] | [next] | [standalone]


#91818

FromBartC <bc@freeuk.com>
Date2015-06-02 11:45 +0100
Message-ID<vPfbx.868703$pj.293442@fx16.am4>
In reply to#91730
On 01/06/2015 23:59, BartC wrote:

>> In the new class style, type and class sort of mean the same thing.
>
> I'm developing a new language along the lines of Python,

(After reading some of the rest of the sub-thread, I'm glad I reined in 
some of the proposed changes to my existing language to make it more 
Python-like.

If my simple, no-nonsense approach can avoid discussions about 
philosophy, religion and meta-physics (or whatever the hell the 
sub-thread was about) then that must be a good thing!)

-- 
Bartc

[toc] | [prev] | [next] | [standalone]


#91820

FromRustom Mody <rustompmody@gmail.com>
Date2015-06-02 04:16 -0700
Message-ID<c9932ea3-7124-4b0a-acdf-7eebdbf5fac5@googlegroups.com>
In reply to#91818
On Tuesday, June 2, 2015 at 4:16:02 PM UTC+5:30, BartC wrote:
> On 01/06/2015 23:59, BartC wrote:
> 
> >> In the new class style, type and class sort of mean the same thing.
> >
> > I'm developing a new language along the lines of Python,
> 
> (After reading some of the rest of the sub-thread, I'm glad I reined in 
> some of the proposed changes to my existing language to make it more 
> Python-like.
> 
> If my simple, no-nonsense approach can avoid discussions about 
> philosophy, religion and meta-physics (or whatever the hell the 
> sub-thread was about) then that must be a good thing!)

What is good that each one can only decide in his own private space.
What is historical is public and studying that history would show that
these questions are central to the existence of our field,
[Mark's views nowithstanding]
http://blog.languager.org/2015/03/cs-history-0.html

[toc] | [prev] | [next] | [standalone]


#91847

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-06-02 09:09 -0600
Message-ID<mailman.65.1433257833.13271.python-list@python.org>
In reply to#91730
On Mon, Jun 1, 2015 at 4:59 PM, BartC <bc@freeuk.com> wrote:
> I'm developing a new language along the lines of Python, perhaps a brief
> description of how things are done there might help. Or just give a
> different perspective.
>
> Objects in this language are tagged: there's a code attached to each
> indicating what kind of data is stored. These codes are integers, or
> enumerations, for example:
>
>  Int =    1
>  String = 2
>  List =   3
>  Class =  4
>
> And the following are examples of object instances with their tags:
>
> a is (Int,    42)
> b is (String, "ABCXYZ")
> c is (List,   [10,20,30,40])
> d is (Class,  2 or <String>)
>
> The last one might be tricky to grasp: it's really just a number, but one
> that represents a class or type (or tag). If printed, it could display
> <String> rather than just 2. (And when used to do something with the class,
> the 2 might be an index into a set of tables.)
>
> d is not /the/ class itself, but just a reference to it (this is pseudo-code
> not Python):
>
> print (b)                 =>  ABCXYZ
> print (typeof(b))         =>  String <2>
>
> print (d)                 =>  String <2>
> print (typeof(d))         =>  Class  <4>
> print (typeof(typeof(d))) =>  Class  <4>
>
> In my own language, the connection between class and type is hazy (I've only
> just added classes so it needs to be hazy until I understand them more).
>
> 'Type' includes everything, including all the built-in types such as the
> tags above, but also user-defined classes. In fact classes are the mechanism
> used to define new types. But with both designated by an integer within the
> same band (eg. built-int types 1 to 20, user-defined classes 21 and up), it
> is easier not to have a strong distinction ... at the moment.
>
> I haven't a root class yet that is the base of all the others. I don't think
> it's necessary internally to make things work. But it might be a useful
> concept in the language. Calling it 'object' however might give rise to
> confusion as 'object' is informally used to refer to instances. (I've never
> used OO but have picked up some of the jargon!)
>
> (This is almost certainly not how Python does things. Although the Python
> language doesn't go into details as to its implementation provided the
> behaviour is correct.)

It sounds quite similar to me. In CPython at least, every object has a
direct pointer to its type rather than an array index (which is
essentially just an offset from a pointer).

[toc] | [prev] | [next] | [standalone]


#91735

FromTheDoctor <dreamingforward@gmail.com>
Date2015-06-01 17:24 -0700
Message-ID<bb48ac94-c2ac-4874-9c95-7ac2280fd5bc@googlegroups.com>
In reply to#91659
On Monday, June 1, 2015 at 7:03:49 AM UTC-5, Eddilbert Macharia wrote:
> I think i kind of understand now. 
> 
> Instead of python having data types like int, string, e.t.c it has two primitive types which are class type and class object which are created by python interpreter during its setup .using this two classes python is able to create some more data types

Eddibert, don't let this crowd (Terry, Stephen, et al.) confuse you.  They are as confused about it as you are.  

The truth is, that they've told a lie to themselves (everything is an object) to hide some details FROM THEMSELVES in their model.  They climb a ladder of ambiguity anytime there's a new problem in their model and call it a "type", or they pull out the "metaclass" term (because no one really knows that that is, so they feel *pretty* safe).

A type is not an object in the same way an instantiated type is an object -- anymore than a blueprint for a building is the building itself.

The reason this confusion appears is for the exact reason I said on an earlier thread:  Python does not define classes in it's grammar -- so it can't account for the difference between an [instantiated] object and it's definition/type.

Mark

[toc] | [prev] | [next] | [standalone]


#91737

FromChris Angelico <rosuav@gmail.com>
Date2015-06-02 10:32 +1000
Message-ID<mailman.28.1433205179.13271.python-list@python.org>
In reply to#91735
On Tue, Jun 2, 2015 at 10:24 AM, TheDoctor <dreamingforward@gmail.com> wrote:
> On Monday, June 1, 2015 at 7:03:49 AM UTC-5, Eddilbert Macharia wrote:
>> I think i kind of understand now.
>>
>> Instead of python having data types like int, string, e.t.c it has two primitive types which are class type and class object which are created by python interpreter during its setup .using this two classes python is able to create some more data types
>
> Eddibert, don't let this crowd (Terry, Stephen, et al.) confuse you.  They are as confused about it as you are.
>
> The truth is, that they've told a lie to themselves (everything is an object) to hide some details FROM THEMSELVES in their model.  They climb a ladder of ambiguity anytime there's a new problem in their model and call it a "type", or they pull out the "metaclass" term (because no one really knows that that is, so they feel *pretty* safe).
>
> A type is not an object in the same way an instantiated type is an object -- anymore than a blueprint for a building is the building itself.

And don't let dreamingforward confuse you, because he is flat-out
wrong. An integer is an object, because you can manipulate it as one.
A function is an object. A dictionary is an object. And a type is an
object too. There is no significant difference here.

ChrisA

[toc] | [prev] | [next] | [standalone]


#91744

FromTheDoctor <dreamingforward@gmail.com>
Date2015-06-01 18:02 -0700
Message-ID<3ee816c0-b3f3-4a0f-b567-40c435a53e8d@googlegroups.com>
In reply to#91737
On Monday, June 1, 2015 at 7:33:11 PM UTC-5, Chris Angelico wrote:
> On Tue, Jun 2, 2015 at 10:24 AM, TheDoctor <dreamingforward@gmail.com> wrote:
> > A type is not an object in the same way an instantiated type is an object -- anymore than a blueprint for a building is the building itself.
> 
> And don't let dreamingforward confuse you, because he is flat-out
> wrong. An integer is an object, because you can manipulate it as one.

An integer in Python *acts* like an object, in some narrow sense can indeed be said to BE one.  But no one uses them like that in practice (purity was trying to beat practicality in the case of ints) -- they use them like ints, with the extra super-nice shortcuts of having them arbitrarily-sized.  And that was available before the type-class unification.

> A function is an object. A dictionary is an object. 

Yep.

> And a type is an
> object too. 

OOPs.

Mark

[toc] | [prev] | [next] | [standalone]


#91803

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-06-02 16:30 +1000
Message-ID<556d4d7b$0$11123$c3e8da3@news.astraweb.com>
In reply to#91744
On Tuesday 02 June 2015 11:02, TheDoctor wrote:

> On Monday, June 1, 2015 at 7:33:11 PM UTC-5, Chris Angelico wrote:
>> On Tue, Jun 2, 2015 at 10:24 AM, TheDoctor <dreamingforward@gmail.com>
>> wrote:
>> > A type is not an object in the same way an instantiated type is an
>> > object -- anymore than a blueprint for a building is the building
>> > itself.
>> 
>> And don't let dreamingforward confuse you, because he is flat-out
>> wrong. An integer is an object, because you can manipulate it as one.
> 
> An integer in Python *acts* like an object, in some narrow sense can
> indeed be said to BE one.

No, they *really are* objects. You can look at the source code of the Python 
interpreter to see how ints are implemented, and they are implemented as 
objects. You can see that they are bigger than a machine int:

py> sys.getsizeof(23)
14

That's 14 bytes. A machine int is typically 2 bytes (int16), 4 bytes (int32) 
or 8 bytes (int64).

If you use ctypes, I expect that you can investigate the internal structure 
of the int. If not in ctypes, then you can certainly do so from a C 
extension.



> But no one uses them like that in practice

Of course they do. ints have methods:

py> n = 23
py> n.to_bytes(5, "big")
b'\x00\x00\x00\x00\x17'


Is that object oriented enough for you?




-- 
Steve

[toc] | [prev] | [next] | [standalone]


#91753

FromTheDoctor <dreamingforward@gmail.com>
Date2015-06-01 18:15 -0700
Message-ID<e7de5af9-1775-4ace-a5a8-e1481a3cc910@googlegroups.com>
In reply to#91737
On Monday, June 1, 2015 at 7:33:11 PM UTC-5, Chris Angelico wrote:
> And a type is an
> object too. There is no significant difference here.

Let me make this clearer to you, Chris, because I don't want you to have to suck it too, like the rest of this community.

A type is not an object.  You see it as one, because you are MENTALLY lexing your own code on the screen.  But python does not define a type.  It defines certain primitives, like strings and integers.  But it doesn't define what an OBJECT is.  So you and everyone else are beating around the bush trying to define something that the LANGUAGE ITSELF doesn't define.  So, don't make a claim about it.  

In Python 2.7 type(type) is type (not object), but isinstance(type, object) is true -- so it is ambiguous, even contradictory, in the language.

Boom.  Suck it.

Mark

[toc] | [prev] | [next] | [standalone]


#91759

FromChris Angelico <rosuav@gmail.com>
Date2015-06-02 11:30 +1000
Message-ID<mailman.32.1433208637.13271.python-list@python.org>
In reply to#91753
On Tue, Jun 2, 2015 at 11:15 AM, TheDoctor <dreamingforward@gmail.com> wrote:
> Let me make this clearer to you, Chris, because I don't want you to have to suck it too, like the rest of this community.
>
> A type is not an object.  You see it as one, because you are MENTALLY lexing your own code on the screen.  But python does not define a type.  It defines certain primitives, like strings and integers.  But it doesn't define what an OBJECT is.  So you and everyone else are beating around the bush trying to define something that the LANGUAGE ITSELF doesn't define.  So, don't make a claim about it.
>
> In Python 2.7 type(type) is type (not object), but isinstance(type, object) is true -- so it is ambiguous, even contradictory, in the language.
>

I'm not saying this for dreamingforward's benefit, as he clearly isn't
interested in learning, but in case the OP is confused: Checking the
type of something doesn't tell you what it isn't. The isinstance check
is true, because type is an instance of type, which is a subclass of
object, therefore type is an instance of object. Similarly, you could
check this:

>>> issubclass(type, object)
True

So you can see that a type IS an object.

ChrisA

[toc] | [prev] | [next] | [standalone]


Page 1 of 5  [1] 2 3 4 5  Next page →

Back to top | Article view | comp.lang.python


csiph-web