from muster import Model, Member
class A(Model):
x = Member()
_x_old : "before setting x"
_x_change : "after setting x"
def _x_old(self, member, data):
data["old"] = getattr(self, "x", None)
def _x_change(self, member, data):
msg = "x : %r => %r"
info = (data["old"], data["value"])
print(msg % info)
A().x = 1
x : None => 1
A().x = 2
A().x = 0
x : None => 2 x : None => 0
# A().x['Thing'] = 1
import inspect
inspect.currentframe().f_back.f_locals
{'code_obj': <code object <module> at 0x000000000610E390, file "<ipython-input-26-cdbe9657c3b0>", line 3>, 'old_excepthook': <bound method IPKernelApp.excepthook of <ipykernel.kernelapp.IPKernelApp object at 0x000000000053A7F0>>, 'outflag': 1, 'result': <ExecutionResult object at 60fed68, execution_count=26 error_before_exec=None error_in_exec=None result=None>, 'self': <ipykernel.zmqshell.ZMQInteractiveShell at 0x4e151d0>}
import re
s = ['before setting x', 'something else']
term = 'before'
%timeit tuple(filter(lambda x: term in x, s))
The slowest run took 6.58 times longer than the fastest. This could mean that an intermediate result is being cached. 1000000 loops, best of 3: 1.04 µs per loop
rx = re.compile('^before (.*)$')
%timeit m = list(map(rx.match, s))
The slowest run took 4.08 times longer than the fastest. This could mean that an intermediate result is being cached. 1000000 loops, best of 3: 1.36 µs per loop
class A(object):
def dothis(self):
print('I am from A class')
class B(A):
pass
class C(object):
def dothis(self):
print('I am from C class')
class D(B, C):
pass
d_instance= D()
d_instance.dothis()
print(D.mro())
I am from A class [<class '__main__.D'>, <class '__main__.B'>, <class '__main__.A'>, <class '__main__.C'>, <class 'object'>]