473,472 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

wrapping problem with old-style class

I have a problem I would like some advice on.

We have a Python binding to the Intersystems Cache OO database. It
provides an old style class in Python as an in memory instance of a
Cache class, and this is a intersystems.pythonbind.object type (= ipo).

The ipo class has three basic methods, namely, get, set, and
run_obj_method (which takes the Cache class method, as its first
argument, and the list of its arguments as the second argument)

e.g.
>>CacheClass=ipo()
CacheClass.set('Name','John')
valName = CacheClass.get('Name')
print valName
'John'

I want to add functionality to ipo, so I have wrapped a new style class
(MyWrapper class, very basic) around it.

PythonCacheClass=MyWrapper(CacheClass)

Now, I want to make PythonCacheClass more pythonic, so I have a
dictionary of all the properties and values of each ipo. Eg

dicCacheProperties = {'Name':'John', 'Address':'The Strand'} etc
for key, val in dicCacheProperties.iteritems():
setattr(PythonCacheClass, key, val)

So now I have:
>>>print PythonCacheClass.Name
'John'

My problem is this: how do I link the set and get methods of the ipo
class with the set and get methods in the wrapper class
PythonCacheClass?

So, I would like the following code:
>>PythonCacheClass.Name='Alexander'
to execute automatically
CacheClass.set('Name','Alexander') etc

My thinking is that inside the PythonCacheClass, I can reference the
ipo class by self.get() - is this right? If so, how then do I set the
set attribute of the PythonCacheClass to automatically run

self.get().set('Name','Alexander')

I hope this is sufficiently clear. Am I tackling the problem the right
way?

Dec 19 '06 #1
1 1091

manstey wrote:
The ipo class has three basic methods, namely, get, set, and
run_obj_method (which takes the Cache class method, as its first
argument, and the list of its arguments as the second argument)

e.g.
>CacheClass=ipo()
CacheClass.set('Name','John')
valName = CacheClass.get('Name')
print valName
'John'

I want to add functionality to ipo, so I have wrapped a new style class
(MyWrapper class, very basic) around it.

PythonCacheClass=MyWrapper(CacheClass)

Now, I want to make PythonCacheClass more pythonic, so I have a
dictionary of all the properties and values of each ipo. Eg

dicCacheProperties = {'Name':'John', 'Address':'The Strand'} etc
for key, val in dicCacheProperties.iteritems():
setattr(PythonCacheClass, key, val)

So now I have:
>>print PythonCacheClass.Name
'John'

My problem is this: how do I link the set and get methods of the ipo
class with the set and get methods in the wrapper class
PythonCacheClass?

So, I would like the following code:
>PythonCacheClass.Name='Alexander'
to execute automatically
CacheClass.set('Name','Alexander') etc
Maybe try:

class WrapperClass(BaseClass, object):

get = object.__getattribute__
set = object.__setattr_

Gerard

Dec 19 '06 #2

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

Similar topics

13
by: Roy Smith | last post by:
I've got a C library with about 50 calls in it that I want to wrap in Python. I know I could use some tool like SWIG, but that will give me a too-literal translation; I want to make some...
11
by: yawnmoth | last post by:
word wrapping normally treats some spaces as line feeds, if there hasn't been a line feed for quite a while. so while a string with eighty consecutive a's might not word wrap, a space placed...
2
by: dam_fool_2003 | last post by:
My understanding about wrapping is that we add utilities to a lib function for our specific use. So days ago in the c.l.c I saw a function def as: void * xmalloc (size_t size) { register void...
5
by: Michael Dyremo | last post by:
Hello. We have a web-application built in ASP.NET using WebForms and Remoting. When selling this application we always incorporate it into the customers existing web-site. Our latest customer...
2
by: Scott | last post by:
I having a problem where I need to turn off the wrapping feature for all columns in my datagrid. Example code would be: <asp:DataGrid id="ResultGrid" runat="server" AutoGenerateColumns="true">...
8
by: Nathan | last post by:
I am trying to prevent a horizontal list from wrapping. Each list item is floated with "float: left". Currently I use an ugly hack. I set the width of the list to a large number which is...
6
by: Markus Ernst | last post by:
Hi Searching for a possibility to display some text with preserved white space and line breaks, but with long lines being wrapped, I found this CSS declaration, which I found helpful: pre {...
8
by: bob | last post by:
Hi, we're faced with a horrible scenario whereby we are not able to access exported classes in a DLL due to cross compiler issues. Traditional approaches such as using extern "C" and...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
2
by: Anish Chapagain | last post by:
Hi!! I'm new to python and have a task for Wrapping up an old program written in C(20.c files), to provide GUI and chart,graph feature in Python. I've tried using SWIG but am not getting well in...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.