Well I'm just learning Python and I'm experiencing some strange behavior. I guess that garbage collector is responsible for that but I'm not sure.
SORRY LADS I MESSED UP THE QUESTION
I wanted reproduce some weirdness I was getting while using some library without that library but I failed miserably.
So second try:
I'm using python API of Autodesk Maya. It is just python wrap around existing C++ API.
So this code:
import maya.OpenMaya as om
Q = om.MQuaternion(1,2,3,4).conjugateIt()
P = om.MQuaternion(6,6,6,6)
print(Q[0],Q[1],Q[2],Q[3])
print(type(Q))
print(type(P))
produces this output:
(6.0, 6.0, 6.0, 6.0)
<class 'maya.OpenMaya.MQuaternion'>
<class 'maya.OpenMaya.MQuaternion'>
So both P,Q
are of type MQuaternion
but Q
does not hold the data it should hold.
Here you can find documentation for MQuaternion
class. conjugateIt
is conjugation in place and returns by reference.
So what went wrong now ?
Here goes the old question which is just wrong :D
In C++ I'm used to do thing like this.
complex<float> c = complex<float>(1,2).conjInPlace()
conjInPlace() is conjugation in place
But if I do something similar in python I get into trouble
class testClass:
def __init__(self,_a,_b):
self.a = _a
self.b = _b
def alterMe(self):
self.b = 123
A = testClass(1,2)
A.alterMe()
print(A.a,A.b)
B = testClass(0,0)
B = testClass(3,4).alterMe()
print(B)
gives me output:
1 123
None
I guess that because object returned by testClass(3,4)
is not immediately referenced by something so it gets deleted.
So why is this happening? How to watch out for this kind of things?