doing a comparison in python

Paul Koning paul_koning@dell.com
Tue Aug 17 10:59:00 GMT 2010


On Aug 16, 2010, at 9:40 PM, Thiago Jung Bauermann wrote:

> On Mon, 2010-08-16 at 17:34 -0700, Mathew Yeates wrote:
>> On Mon, Aug 16, 2010 at 5:26 PM, Michael Snyder <msnyder@vmware.com> wrote:
>>> Mathew Yeates wrote:
>>>> I am debugging fortran code and I want to see if an interior value is
>>>> equal to .FALSE.
>>>> I know how to get the value with parse_and_eval but what do I do with it?
>>> 
>>> Can we assume this value is an integer?
>>> Then you should be able to do something like this:
>>> 
>>>  long foo = value_as_long (parse_and_eval (my_value));
>>> 
>>>  if (foo == 0)
>>>     [...];
>> 
>> no. it's a logical. Either .TRUE. or .FALSE.
> 
> GDB values in Python scripts can be directly compared with Python's
> native types, so you can just say:
> 
> foo = gdb.parse_and_eval ("foo")
> if foo == True:
>  print 'hooray'
> -- 

That's a bit redundant, just as it would be in C.  I would write:

foo = gdb.parse_and_eval ("foo")
if foo:
   print 'hooray'
--
	paul



More information about the Gdb mailing list