not tom eastman
TRANSCRIPT
Not Tom Eastmanby Not Katie McLaughlin
class TomEastman(object): def whoami(self): return 'Tom Eastman’
tom_eastman = TomEastman()
print(tom_eastman.whoami())
Tom Eastman
class KatieMcLaughlin(object): def whoami(self): return 'Katie McLaughlin’
katie_mclaughlin = KatieMcLaughlin()
print(katie_mclaughlin.whoami())
Katie McLaughlin
if not tom_eastman: print('not Tom Eastman') else: print('Tom Eastman')
Tom Eastman
if not TomEastman: print('not Tom Eastman') else: print('Tom Eastman')
Tom Eastman
if katie_mclaughlin is not tom_eastman: print('Katie is not Tom') else: print('Katie is Tom')
Katie is not Tom
if katie_mclaughlin is not katie_mclaughlin: print('Katie is not Katie') else: print('Katie is Katie')
Katie is Katie
if not isinstance(katie_mclaughlin, TomEastman): print('Katie McLaughlin') else: print('not Katie McLaughlin')
Katie McLaughlin
from wrapt import ObjectProxy
class KatieMcLaughlin(ObjectProxy): pass
tom_eastman = TomEastman() katie_mclaughlin = KatieMcLaughlin(tom_eastman)
print(tom_eastman.whoami())
print(katie_mclaughlin.whoami())
Tom Eastman
Tom Eastman
if isinstance(katie_mclaughlin, TomEastman): print('Tom Eastman') else: print('not Tom Eastman')
Tom Eastman
if isinstance(katie_mclaughlin, KatieMcLaughlin): print('Katie McLaughlin') else: print('not Katie McLaughlin')
Katie McLaughlin
if type(katie_mclaughlin) == TomEastman: print('Tom Eastman') else: print('not Tom Eastman')
not Tom Eastman
What have we learnt?
More than one way to skin a cat
not
== !=
is is not
isinstance() type() __class__
__bool__() __int__()
id()
class GrahamDumpleton(object): def whoami(self): return 'Graham Dumpleton'
graham_dumpleton = GrahamDumpleton()
print(not isinstance(graham_dumpleton, (TomEastman, KatieMcLaughlin)))
True