Python

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • question about metaclasses

    1 answers - 252 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    hi pygurus
    can you please tell me why we need metaclasses and how to use them
    thanks a lot
    Anil
    Do you Yahoo!?
    Everyone is raving about the all-new Yahoo! Mail Beta.
    Tutor maillist - Tutor (AT) python (DOT) org
  • No.1 | | 1689 bytes | |

    anil maran wrote:
    hi pygurus
    can you please tell me why we need metaclasses and how to use them

    Hmmmetaclasses are an advanced topic, first exposure to them usually
    causes one's brain to explode. Fortunately the condition is only
    temporary :-)

    Basically a metaclass is the type of a class, or the type of a type.
    Think about it this way - every object has a type. The type of 1 is int,
    the type of 'a' is str.

    In [16]: type(1)
    [16]: <type 'int'>

    In [17]: type('a')
    [17]: <type 'str'>

    Note that <type 'int'is just the printed representation of the type int:
    In [19]: type(1) == int
    [19]: True

    In [20]: print int
    <type 'int'>

    But int and str are themselves objects - what is their type?

    In [18]: type(int)
    [18]: <type 'type'>

    In [21]: type(str)
    [21]: <type 'type'>

    Why might you care? In general, it is the type of an object that
    determines its behaviour. The behaviour of an int is determined by the
    int type. What determines the behaviour of a class? Its type! So if you
    want to customize the behaviour of a class, you create a custom metatype
    for the class.

    That is a very brief introduction. Here are some relatively introductory
    articles. You can find more examples by searching the Python Cookbook
    and comp.lang.python for "metaclass". Don't expect to understand this
    the first time.

    Here is Guido's brief explanation:
    #metaclasses

    Kent

    Tutor maillist - Tutor (AT) python (DOT) org

Re: question about metaclasses


max 4000 letters.
Your nickname that display:
In order to stop the spam: 7 + 6 =
QUESTION ON "Python"

EMSDN.COM