[IronPython] ValueError: cannot assign to value types

Count László de Almásy calmasy at gmail.com
Sat Aug 8 05:40:42 CEST 2009


i'm really stuck trying to change values for an object of type
'Parcel', which comes from the openmetaverse library i'm using. how
this library is implemented i don't have control over, but the given
interface is to make local changes to these Parcel objects, then use
its Update() method to commit the changes. but it seems in IronPython
i can't change these objects.

>>> type(props)
<type 'Parcel'>

>>> props.Name = "Yes"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot assign to value types

after hours of struggling, i found
http://ironpython.codeplex.com/Wiki/View.aspx?title=Value%20Types
which seems to explain why i'm being bit here. bit it also says
"updates are still possible via instance methods on the value type
itself." so isn't "__setattr__" an instance method? seems i'm not able
to use that either:

>>> props.__setattr__("Name", "Yes")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Attempt to update field 'Name' on value type 'Parcel';
value type fields cannot be directly modified

ok, so what are my options? how do i get around this? i *have* to be
able to update objects of this type somehow.

i can create a new object of that type, but the constructor doesn't
allow me to pre-stock it with values ( since i guess it assumes i'll
be able to change them later), and then of course once it's created i
can't change anything.

-- 
Cheers, László



More information about the Ironpython-users mailing list