class, instance, object, attribute, method, type (__class__)
instance variables: <object>.__dict__
class variables:
<class>.__dict__
<class>.class_var = 1
superclass methods:
special methods:
__name__
__getattribute__
magic methods
Inheritance
Polymorphism
arguments
*args
: tuple (a,b,c)
**kwargs
: dictionary {}
decorators
class Classe:
class_var = 0
def __init__(self):
self.instance_var = 0
Classe.class_var += 1
class SubClasse(Classe):
pass
def simple_decorator(own_funct):
def internal_wrapper(*args,**kwargs)
print("pre-execution")
own_function(*args,**kwargs) # original method executed
return internal_wrapper
@simple_decorator
def decorators(*args,**kargs):
pass
def simple_decorator_attributes(attribute):
def wrapper(our_funct):
def internal_wrapper(*args):
pass
return internal_wrapper
return wrapper
@simple_decorator_attributes('argument')
def decorators_with_attribute(*args):
pass
@simple_decorator
@simple_decorator_attributes('other_argument')
# simple_decorator( simple_decorator_attributes( funcion() ) )
class SimpleDecoratorClass:
def __init__(self, own_funct):
self.func = own_funct
def __call__(self,*args,**kwargs):
print(self.func.__name__)
self.func(*args,**kwargs)
class SimpleDecoratorClassWithArguments:
def __init__(self,argument):
pass
def __call__(self,own_funct)
@SimpleDecoratorClass
def simple_function(*args,**kwargs):
pass
def object_counter(class_):
class_.__getattr__orig = class_.__getattribute__
def new_getattr(self, name):
if name == 'mileage':
print('We noticed that the mileage attribute was read')
return class_.__getattr__orig(self, name)
class_.__getattribute__ = new_getattr
return class_
@object_counter
class Car:
def __init__(self, VIN):
self.mileage = 0
self.VIN = VIN