From: aahz at netcom.com (Aahz Maruch)
Date: Mon, 26 Apr 1999 21:22:24 GMT
Subject: converting perl to python - simple questions.
References: <7fvagp$8lm$1@nnrp1.dejanews.com> <aahzFAr5Dt.MLF@netcom.com> <x1ju2u3xmo0.fsf@unhinged.engr.sgi.com>
Message-ID: <aahzFAtFDD.7Iy@netcom.com>
Content-Length: 1024
X-UID: 1516                                                  

In article <x1ju2u3xmo0.fsf at unhinged.engr.sgi.com>,
Chad McDaniel  <chadm at sgi.com> wrote:
>aahz at netcom.com (Aahz Maruch) writes:
>> In article <7fvagp$8lm$1 at nnrp1.dejanews.com>,
>>  <sweeting at neuronet.com.my> wrote:
>>>
>>>a) Perl's "defined".
>>>   [perl]
>>>   if (defined($x{$token})
>>>
>>>   [python]
>>>   if (x.has_key(token) and x[token]!=None) :
>> 
>> That looks correct.  Thankfully Python does have short-circuit
>> evaluation.  Note that if you normally expect x[token] to have a value,
>> you might restructure the code a bit to use try/except.
>
>wouldn't x.get() work more elegantly:
>---
>if (x.get(token)) :
>  [do stuff]

Yup.  I keep forgetting about that one.  Note that (cf recent thread)
"if ( not x.get(token) is None ) :" is faster in many cases.
-- 
                      --- Aahz (@netcom.com)

Hugs and backrubs -- I break Rule 6       <*>      http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het

Hi!  I'm a beta for SigVirus 2000!  Copy me into your .sigfile!




