Re: [python] acessing struct elements

Daniel Jacobowitz
2008-08-13T12:38:33Z

On Wed, Aug 13, 2008 at 01:46:53AM -0300, Thiago Jung Bauermann wrote:
> There's one unexpected consequence of this: to enable the syntax above, all
> gdb.Value objects need to implement the map methods, and Python considers
> empty maps to be False in contexts which expect a boolean. Because of this,
> the following will not generally work:
>
> val = frame.read_var_value (sym)
> if val:
> print "Variable value is: " + str (val)
> else:
> print "Variable not found."

It took me a while to find it, but I knew there was an operator for
this. Take a look at __nonzero__:

http://docs.python.org/ref/customization.html

--
Daniel Jacobowitz
CodeSourcery