473,394 Members | 1,828 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,394 software developers and data experts.

proxy class and __add__ method


Hello,
I have written the following small proxy class which I expect to pass all
function calls to the 'original' object:

--- BEGIN ---
class proxy(object):
def __init__( self, subject ):
self.__subject = subject
def __getattr__( self, name ):
return getattr( self.__subject, name )

prx_i=proxy(1)
print hasattr(prx_i,'__add__')
j=prx_i.__add__(1)
k=prx_i+1
--- END ---

Actually the "hasattr(prx_i,'__add__')" returns "True" as expected, and
"j=prx_i.__add__(1)" sets j=2.

But "k=prx_i+1" raises a
<type 'exceptions.TypeError'>: unsupported operand type(s) for +: 'proxy'
and 'int'.

How is this addition different from the previous line "j=..."? And how can I
modify the proxy class so that all methods are passed on, which are not
explicitly overloaded?

Regards,
Magnus
--
View this message in context: http://www.nabble.com/proxy-class-an...p18715799.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jul 29 '08 #1
0 959

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

Similar topics

2
by: nitrogenycs | last post by:
Hello, I need a way to get a notification whenever a variable of an object changes. The approach should be non-intrusive so that I can use existing objects without modifying them. I want to be...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
7
by: Steven D'Aprano | last post by:
I'm having problems with sub-classes of built-in types. Here is a contrived example of my subclass. It isn't supposed to be practical, useful code, but it illustrates my problem. class...
2
by: cfriedalek | last post by:
Sorry for the vague subject. Not sure what the right terminology is. How can I use an instance's data by reference to the instance name, not the instance attribute? OK the question is probably...
10
by: roberto | last post by:
I'm to deploy a .NET DLL which internally communicates with the WS. I don't want others to see internal complexity of the web service classes generated by "Add a Web reference" VS option. As a...
2
by: Bill Jackson | last post by:
For example, class A: def __init__(self,a): self.a = a def __eq__(self, other): return self.a == other.a class B: def __init__(self,b):
37
by: minkoo.seo | last post by:
Hi. I've got a question on the differences and how to define static and class variables. AFAIK, class methods are the ones which receives the class itself as an argument, while static methods...
2
by: gartnerjmoody | last post by:
I have a web service that has a method that takes a created .NET class like this: method(my.Shared.BO.InfoClass info, bool isItem) The actual web service gets this class from an assembly,...
0
by: Magnus Schuster | last post by:
With this explanation the behaviour is absolutely clear. Can I find some documentation anywhere containing more background information how magic functions are resolved? I haven't been successful...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.