← Back to team overview

yade-dev team mailing list archive

Re: Python question ?

 

> I noticed few days ago that if I try to access an engine's attribute 
> which doesn't exist, a clear error message is displayed.
> Exampli gratia, if I do:
> 
> triax=utils.typedEngine('TriaxialCompressionEngine')
> triax.PAPULA
> 
> I get an error like this 'TriaxialCompressionEngine' object has no 
> attribute 'PAPULA'.
> 
> But if I do:
> 
> triax=utils.typedEngine('TriaxialCompressionEngine')
> triax.PAPULA=5
> 
> I have no error, but a new attribute is created, named PAPULA (fortunately).

Hi Emanuele,

this is the way it is supposed to work in python: class defines "class
attributes", but you can also create "instance attribute" (defined for
that instance only) by assigning value to it -- just like by assigning
"a=3", you create variable "a".

I had the same problem once, but looking through google didn't reveal
anything. Since I think it _is_ a problem (as we always want python
wrapper objects to reflect c++ objects 1:1, without some extra stuff), I
put the question at boost::python mailing list.

I will let you know if I have some answer; if so, I will change the code
to raise AttributeError insted of creating the new instance attribute.
For the moment, we're out of luck with that, though.

Cheers, Vaclav





Follow ups

References