Reputation: 53
I've defined a ctypes variable:
abc=ctypes.c_double.from_buffer(struct, STRUCT.field_1.offset)
abc
represents field_1 of a ctypes structure instance struct
with class definition STRUCT
. Later, if I want to modify the value of abc
, I have to do like this:
abc.value=1.0
which will also change the value of struct.field_1
as I expect.
Upon modifying the value of abc
, however, I could have no idea what the datatype of abc
is, so simply using conventional syntax
abc=1.0
will redefine abc
as a normal python variable and struct.field_1
will not change accordingly. How can I change value of struct.feild_1
through abc
using conventional python syntax?
Upvotes: 2
Views: 1872
Reputation: 76693
This isn't possible -- in Python, the behavior of names (or 'variables') isn't configurable, only the behavior of objects (or 'values'). Plain old foo =
rebinds a name, it doesn't rely on any object behavior to do so.
You might find http://nedbatchelder.com/text/names.html elucidating.
Upvotes: 2