473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Twice bound method

Hi!

I want to instrumentate a class with a number of getter/setters.
Each pair of getter/setter must keep it's own state gsState but also
access to the state iState of instances of the instrumentated class.
For example:

class GetterSetter:
def __init__(gsInstance, gsState):
....
def get(gsInstance, iInstance, attr):
....
def set(gsInstance, iInstance, attr, value):
....

class Instrumentated:
def __init__(iInstance, iState):
....

getterSetter = GetterSetter(gsState1)
Instrumentated.getter1 = getterSetter.get
Instrumentated.setter1 = getterSetter.set

getterSetter = GetterSetter(gsState2)
Instrumentated.getter2 = getterSetter.get
Instrumentated.setter2 = getterSetter.set

instrumentated = Instrumentated(...)
instrumentated.getter1("x")
instrumentated.setter2("x", 5)

At first sight I thought that the above would work fine
as getterSetter.get would bind the getter to the GetterSetter
instance and then instrumented.getter1 would bind the already
bound getter to the Instrumentated instance, so at the end
an invocation like instrumentated.getter1("x") would be calling the
original getter passing a GetterInstance as first implicit
argument, an Instrumented instance as a second one and "x"
as the third -explicit- one. Well, the fact is that the getter
is only bound to the last instance, there are no nested bindings.

Another solution could come from the use of function nested
lexical scopes and closures, with a factory function which
takes the gsState as argument and produces a getter (or setter)
function taking an iState as first argument and the attribute as
second one. Then the class can be instrumentated with the generated
getter (or setter) which keeps the gsState captured within its closure.
For example:

def getterGen(gsState):
def getter(iState, attr):
....
return getter

Instrumentated.getter1 = getterGen(gsState1)
Instrumentated.getter2 = getterGen(gsState2)

Do you know of another -elegant- solution for the above problem?
Is there any way to get the nested method binding behaviour that
the first failed attempt required?

Thank you in advance.
Regards,
Carlos

Aug 27 '05 #1
0 882

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Russell E. Owen | last post by:
I have several situations in my code where I want a unique identifier for a method of some object (I think this is called a bound method). I want this id to be both unique to that method and also...
8
by: Kevin Little | last post by:
#!/usr/bin/env python ''' I want to dynamically add or replace bound methods in a class. I want the modifications to be immediately effective across all instances, whether created before or...
7
by: Douglas | last post by:
I have a frontend and backend database , program.mde and data.mdb on a client PC. How do i prevent them launching the program.mde more than once on a single PC? Somtimes they minizmise the program...
14
by: V. Jenks | last post by:
I'm a little rusty having not touched .NET for 6 months and I can't remember why Page_Load is happening twice in this code: private void Page_Load(object sender, System.EventArgs e) {...
8
by: MaryA | last post by:
I have an aspx page that loads twice inspite of using the IsPostBack i removed all controls from the page and still the page_load event is called twice I appriciate any help coz i have lost...
8
by: TS | last post by:
Hi, i have inherited a page from another user. The page is the target frame in a frameset. for some reason the whole page runs twice (page_load, init, etc. all run twice) I can't figure out how...
2
by: =?Utf-8?B?VG9tw6FzIE1hcnTDrW5leg==?= | last post by:
Hi, I recently converted an ASP.NET project for framework 2.0. I never had any problem using VS 2003 but today, debugging a page, I get surprised when I saw that once debugged the last line, it...
11
by: fiefie.niles | last post by:
I am using ASP.NET 2005 and I have a simple form. Page_Load calls a sub mySub that does not do anything (for testing purposes). But, Page_Load gets called twice. On every single ASPX page in my...
11
by: Mathias Panzenboeck | last post by:
Hi. I have a problem with weak refs and bound methods. The best explanation for the problem is a short bit of code. I have the three classes Wrapper, Foo and Bar: import weakref class...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.