48 lines
1.2 KiB
Plaintext
48 lines
1.2 KiB
Plaintext
From: aahz at netcom.com (Aahz Maruch)
|
|
Date: Sun, 25 Apr 1999 15:51:29 GMT
|
|
Subject: converting perl to python - simple questions.
|
|
References: <7fvagp$8lm$1@nnrp1.dejanews.com>
|
|
Message-ID: <aahzFAr5Dt.MLF@netcom.com>
|
|
X-UID: 1356
|
|
|
|
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.
|
|
|
|
>b) RE's.
|
|
> [perl]
|
|
> if ($mytext !~ /^\s$/)
|
|
>
|
|
> [python]
|
|
> if not (re.match('^\s$'), mytext)
|
|
|
|
I think you want
|
|
|
|
if not (re.match('^\s$', mytext)) :
|
|
or
|
|
if not (re.match('^\s*$', mytext)) :
|
|
|
|
(I think that Perl code has a bug in it by not including '*', but I
|
|
could be wrong.)
|
|
--
|
|
--- 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!
|
|
|
|
|
|
|
|
|