How can i assign a specific value for a generic variable name in a object (auto correction purpose)
something like this
# assignation failing (no modification of "pointed" attribut)
for Attribut in [ self.Src, self.Dst, self.Center ] :
if ( type( Attribut ) != cPointXY ) :
Attribut = cPointXY( Attribut )
print( "Result generic : ", self.__dict__ )
# working code
if ( type( self.Src ) != cPointXY ) :
self.Src = cPointXY( self.Src)
print( "Result direct : ", self.__dict__ )
showing that , if self.src is treated in direct it works but generic not due to variable attribut modification, attribut is a copy and not the original variable.
How can i reach the self.Src from his name 'Src' ? dict_ give me the direct value or type but i can't modify this directly.
Precision: it's in the init so getattr/setattr don't work normaly yet a this level
--------- after some other test, setattr work (bug earlier in code) --- so solution is (quick and dirty but not the purpose)
for Attribut in [ "Src", "Dst", "Center" ] :
TypeAttribut = self.__dict__[ Attribut ]
if ( TypeAttribut != cPointXY ) :
setattr( self, Attribut, cPointXY( getattr( self, Attribut ) ) )