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.

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

Reply via email to