473,493 Members | 3,174 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

operator over loading

Hi all,

I have defined q python class and want to know if i can over load '='
operator.

Here is my scenario

Def myClass:
__init__(self,a): # a is C Object
c_obj = a

__del__
delete c object.

b = myClass(c_obj1)
c = myClass(c_obj2)

#python expression
a=tan(sin(b)*cos(c))

Where sin, cos & tan and '*' are over loaded, and the result of this is
assigned to variable a.

Now the problem is cos(c), sin(b) creates new objects, which are used
for multiplication.
This again generates a new object,
What i want to do it automatically delete all intermediate objects.
except the one assigned to a.
currently i am deleteing c object in __del__
So once I reassing some thing else to a that is also getting deleted.
So what i want to do is once i assign it to a variable, i want to set
flag so that i won;t delete it in _del_

Can some some suggest is there any better way of doing the same,
Thanks & Best Regards.
Anand

Jul 18 '05 #1
1 1647
Anand K Rayudu wrote:
Hi all,

I have defined q python class and want to know if i can over load '='
operator.
No you can't - that stems from the fact that assignment in python means that
a value is bound to <name>, not that there is made a copy of that value
stored into some space referred to by <name>, as it is done it C/C++. Think
of variables as references. There is also no &= operator in C++ to
overload.
Now the problem is cos(c), sin(b) creates new objects, which are used
for multiplication.
This again generates a new object,
What i want to do it automatically delete all intermediate objects.
except the one assigned to a.
currently i am deleteing c object in __del__
So once I reassing some thing else to a that is also getting deleted.
So what i want to do is once i assign it to a variable, i want to set
flag so that i won;t delete it in _del_


Why do you care? Let pythons GC do the job for you.

It looks like you try to impose C++ thinking on python here. While thats
understandable, its never good to try to stick to the idioms of one
language in anotherone - you miss the nice differences then :)

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2

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

Similar topics

3
13541
by: A | last post by:
Hi, I understand that operator loading is used to support user-defined types. One of the requirements is that one of the arguments in an operator overloaded function must be of a user defined...
34
6402
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
4
19783
by: Evil Bert | last post by:
Is there anyway to compare a field with multiple string values using LIKE? Here's the statement I have now: SELECT * FROM list WHERE email LIKE CONVERT( _utf8 'hotmail@hotmail.com' USING latin1...
0
879
by: GordonML | last post by:
hi, i have a class based on CString which holds the contents of a file. CString's operator returns a PXSTR ( a char in non-unicode i think ), but this is no use for the left side of an...
0
6989
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
7195
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...
1
6873
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...
1
4889
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
4579
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
3088
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
1400
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 ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
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...

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.