Python vs. Perl, which is better to learn?

Andrew Dalke dalke at dalkescientific.com
Wed May 1 13:27:52 EDT 2002


Alex:
> "Otherwise"...?
>
> >>> a0=re.compile('^a{0}')
> >>> a0.match('')
> <_sre.SRE_Match object at 0x8187fb0>
>
> Of *course* a{0} matches '' -- how could it FAIL to?

Oops, silly me.  I was posting way after my bedtime.  :)

What I meant to say was that if range was to be more Pythonic
("lower-boud-included, upper-bound-excluded") then the single
element repeat count should also be made more Pythonic.

Consider then if
  s = "aaaaa"
in this case,
  s[0] == "a"
which means the equivalent repeat would be
  ^a{0}$
to match "a" and only "a"

But people interpret that as a repeat count (like "a" * 1) rather
than as a slice of sort and it hasn't been a problem.  At least,
I've not seen people surprised by it.

I therefore don't think people have a Pythonic slice expectation
for the {,} construct in regexps.  On the other hand, there aren't
that many people who use this in the first place, so that population
is somewhat self selected.

                    Andrew
                    dalke at dalkescientific.com








More information about the Python-list mailing list