Not Tom Eastman

  • Published on
    18-Mar-2018

  • View
    208

  • Download
    4

Transcript

Not Tom Eastmanby Not Katie McLaughlinclass TomEastman(object): def whoami(self): return 'Tom Eastman tom_eastman = TomEastman() print(tom_eastman.whoami())Tom Eastmanclass KatieMcLaughlin(object): def whoami(self): return 'Katie McLaughlin katie_mclaughlin = KatieMcLaughlin() print(katie_mclaughlin.whoami())Katie McLaughlinif not tom_eastman: print('not Tom Eastman') else: print('Tom Eastman')Tom Eastmanif not TomEastman: print('not Tom Eastman') else: print('Tom Eastman')Tom Eastmanif katie_mclaughlin is not tom_eastman: print('Katie is not Tom') else: print('Katie is Tom')Katie is not Tomif katie_mclaughlin is not katie_mclaughlin: print('Katie is not Katie') else: print('Katie is Katie')Katie is Katieif not isinstance(katie_mclaughlin, TomEastman): print('Katie McLaughlin') else: print('not Katie McLaughlin')Katie McLaughlinfrom wrapt import ObjectProxy class KatieMcLaughlin(ObjectProxy): pass tom_eastman = TomEastman() katie_mclaughlin = KatieMcLaughlin(tom_eastman) print(tom_eastman.whoami()) print(katie_mclaughlin.whoami())Tom EastmanTom Eastmanif isinstance(katie_mclaughlin, TomEastman): print('Tom Eastman') else: print('not Tom Eastman')Tom Eastmanif isinstance(katie_mclaughlin, KatieMcLaughlin): print('Katie McLaughlin') else: print('not Katie McLaughlin')Katie McLaughlinif type(katie_mclaughlin) == TomEastman: print('Tom Eastman') else: print('not Tom Eastman')not Tom EastmanWhat have we learnt?More than one way to skin a catnot== !=is is notisinstance() 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

Recommended

View more >