a new object definition

Bruno Desthuilliers onurb at xiludom.gro
Fri Sep 1 04:58:31 EDT 2006


Sylvain Ferriol wrote:
> hello everybody,
> 
> i want to talk with you about a question i have in mind and i do not
> find a answer. it 's simple:
> why do we not have a beatiful syntax for object definition as we have
> for class definition ?

Python's classes are objects too - instances of their metaclass.

> we can define a class in python in 2 ways:
>  1. by using the metaclass constructor
>    my_class = MyMetaClass(....)
>  2. by using the classic definition syntax:
>    class my_class(object):
>       __metaclass__ = MyMetaClass
> 
> if i want to instanciate an object, i only have one way to define it:
>  my_obj = my_class(....)
>
> why not a better syntax like class syntax ?
>
> example:
>>> instance my_obj:
>>>   __class__ = my_class

I fail to see how it's "better", nor what would be the use case. But
anyway I think it could be possible by using the metaclass as class and
the class as instance. Just make sure the metaclass wraps all methods
into classmethods and you should be done.

> 
> with this syntax, we are coherent between objects and classes.
> why do we have a specific syntax for the class object definition and not
> for objects of different type?
> 
> so if i want to define a new class object (my_class for example) with a
> new object syntax:
>>> instance my_class:
>>>   __class__ = object
>>>   __metaclass__ = MyMetaClass
>>>   ....
> 
> thanks
> 
> Sylvain Ferriol
> Ingénieur de recherche
> Laboratoire TIMC/IMAG
> http://www-timc.imag.fr/
> 


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list