From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3598 invoked by alias); 13 Aug 2008 12:38:33 -0000 Received: (qmail 3508 invoked by uid 22791); 13 Aug 2008 12:38:32 -0000 X-Spam-Check-By: sourceware.org Received: from NaN.false.org (HELO nan.false.org) (208.75.86.248) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 13 Aug 2008 12:37:37 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id 7D96F98243; Wed, 13 Aug 2008 12:37:35 +0000 (GMT) Received: from caradoc.them.org (22.svnf5.xdsl.nauticom.net [209.195.183.55]) by nan.false.org (Postfix) with ESMTP id 5A6E298100; Wed, 13 Aug 2008 12:37:35 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.69) (envelope-from ) id 1KTFbZ-0005Sp-3R; Wed, 13 Aug 2008 08:37:33 -0400 Date: Wed, 13 Aug 2008 12:38:00 -0000 From: Daniel Jacobowitz To: Thiago Jung Bauermann Cc: gdb-patches@sources.redhat.com Subject: Re: [python] acessing struct elements Message-ID: <20080813123732.GA20573@caradoc.them.org> Mail-Followup-To: Thiago Jung Bauermann , gdb-patches@sources.redhat.com References: <20080429155212.444237503@br.ibm.com> <20080429155304.466637516@br.ibm.com> <20080528212451.GB2969@caradoc.them.org> <1215410598.1795.58.camel@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2008-05-11) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-08/txt/msg00342.txt.bz2 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