473,799 Members | 3,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Typ eError'>: 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 996

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

Similar topics

2
1460
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 notified no matter who or what did change the wrapped object - even whenever an object internal methods changes the variables. So I coded the piece of code shown below (just copy and paste it, it's ready-to-run).
166
8687
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
1375
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 MyStr(str): """Just like ordinary strings, except it exhibits special behaviour for one particular value. """ magic = "surprise"
2
1419
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 really poor but hopefully an example will make it clear. <type 'int'> 2 1 3
10
7129
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 WebSerive contains a lot of methods and different types creating a web proxy class manually is too time consuming. I tried to edit a class manually, changing the highest-level access modifiers from public to internal - this way I could use the...
2
2127
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
5486
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 are the one which runs statically with the defining class. Hence, my understanding is that static variables must be bound to the class defining the variables and shared by children of parent class where the variable is defined. But, please have a...
2
1390
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, Shared.BO.dll I have a Windows Workflow that needs to call this, and the Workflow itself is being passed an object of this type (my.Shared.BO.InfoClass) as a property in the workflow. The same Shared.BO.dll that the web
0
265
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 with the Python Language Reference. I am totally clueless how to do this. Below you find my attempt. Neither __getattr__ nor __add__ of the metaclass 'meta' are ever called. May I ask you for some more guidance or corrections to the code below?
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10228
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7565
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.