decoupling a certain method

C

castironpi

class Proxy:
def __init__( self, proxer ):
object.__setattr__( self, '_proxer', proxer )

ComplexObject= object

viewA= type( 'ComplexView', ( Proxy, ComplexObject ), { '__eq__':
lambda self, other: abs( self._proxer- other )<= 1 } )

j= range( 10 )

g= 5
for a in j:
p= viewA( a )
print( p.__class__.__name__, p._proxer, p== g )


Subclassing provides an alternative to delegation and proxying. I got
this far, but I'm lost: How do I allow g= proxy( 5 ) in line 11? Do I
need to?

If I do it, I get:

TypeError line 7: unsupported operand type(s) for -: 'int' and
'ComplexView'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top