Top Banner
Not Tom Eastman by Not Katie McLaughlin
16

Not Tom Eastman

Mar 18, 2018

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Not Tom Eastman

Not Tom Eastmanby Not Katie McLaughlin

Page 2: Not Tom Eastman

class TomEastman(object): def whoami(self): return 'Tom Eastman’

tom_eastman = TomEastman()

print(tom_eastman.whoami())

Tom Eastman

Page 3: Not Tom Eastman

class KatieMcLaughlin(object): def whoami(self): return 'Katie McLaughlin’

katie_mclaughlin = KatieMcLaughlin()

print(katie_mclaughlin.whoami())

Katie McLaughlin

Page 4: Not Tom Eastman

if not tom_eastman: print('not Tom Eastman') else: print('Tom Eastman')

Tom Eastman

Page 5: Not Tom Eastman

if not TomEastman: print('not Tom Eastman') else: print('Tom Eastman')

Tom Eastman

Page 6: Not Tom Eastman

if katie_mclaughlin is not tom_eastman: print('Katie is not Tom') else: print('Katie is Tom')

Katie is not Tom

Page 7: Not Tom Eastman

if katie_mclaughlin is not katie_mclaughlin: print('Katie is not Katie') else: print('Katie is Katie')

Katie is Katie

Page 8: Not Tom Eastman

if not isinstance(katie_mclaughlin, TomEastman): print('Katie McLaughlin') else: print('not Katie McLaughlin')

Katie McLaughlin

Page 9: Not Tom Eastman

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

Page 10: Not Tom Eastman

if isinstance(katie_mclaughlin, TomEastman): print('Tom Eastman') else: print('not Tom Eastman')

Tom Eastman

Page 11: Not Tom Eastman

if isinstance(katie_mclaughlin, KatieMcLaughlin): print('Katie McLaughlin') else: print('not Katie McLaughlin')

Katie McLaughlin

Page 12: Not Tom Eastman

if type(katie_mclaughlin) == TomEastman: print('Tom Eastman') else: print('not Tom Eastman')

not Tom Eastman

Page 13: Not Tom Eastman

What have we learnt?

Page 14: Not Tom Eastman

More than one way to skin a cat

Page 15: Not Tom Eastman

not

== !=

is is not

isinstance() type() __class__

__bool__() __int__()

id()

Page 16: Not Tom Eastman

class GrahamDumpleton(object): def whoami(self): return 'Graham Dumpleton'

graham_dumpleton = GrahamDumpleton()

print(not isinstance(graham_dumpleton, (TomEastman, KatieMcLaughlin)))

True