From: chadm at sgi.com (Chad McDaniel) Date: 26 Apr 1999 11:27:11 -0700 Subject: converting perl to python - simple questions. References: <7fvagp$8lm$1@nnrp1.dejanews.com> Message-ID: X-UID: 192 aahz at netcom.com (Aahz Maruch) writes: > In article <7fvagp$8lm$1 at nnrp1.dejanews.com>, > 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] --- -- -chad