Skip to main content

Home/ Python Programming/ Group items tagged MetaClasses

Rss Feed Group items tagged

Jac Londe

Eli Bendersky's website » Python metaclasses by example - 12 views

    • Mauro De Giorgi
       
      Start read from here
  • Study and understand this example and you’ll grasp most of what one needs to know about writing metaclasses.
  • To control the creation and initialization of the class in the metaclass, you can implement the metaclass’s __new__ method and/or __init__ constructor [6]. Most real-life metaclasses will probably override just one of them. __new__ should be implemented when you want to control the creation of a new object (class in our case), and __init__ should be implemented when you want to control the initialization of the new object after it has been created.
  • ...3 more annotations...
  • It’s important to note here that these print-outs are actually done at class creation time, i.e. when the module containing the class is being imported for the first time. Keep this detail in mind for later.
  • So when the call to MyMeta is done above, what happens under the hood is this:
  • Python metaclasses by example
reckoner reckoner

Metaclass programming in Python - 0 views

  • Metaclass programming in PythonPushing object-oriented programming to the next level
  • New to AOP? You may find this "Introduction to Aspect-Oriented Programming" (PDF) by Ken Wing Kuen Lee of the Hong Kong University of Science and Technology interesting.
reckoner reckoner

Introduction To New-Style Classes in Python - 0 views

  • Here's what new-style classes have to offer: Properties: Attributes that are defined by get/set methods Static methods and class methods The new __getattribute__ hook, which, unlike __getattr__, is called for every attribute access, not just when the attribute can't be found in the instance Descriptors: A protocol to define the behavior of attribute access through objects Overriding the constructor __new__ Metaclasses (not discussed)
1 - 3 of 3
Showing 20 items per page