Python not that wierd
Steve Lamb
grey at despair.rpglink.com
Tue Aug 1 19:49:21 EDT 2000
On Tue, 1 Aug 2000 23:49:17 +0200, Alex Martelli <alex at magenta.com> wrote:
>I think that, to parse '0 or more digits', a \d* might perhaps be better.
>You don't normally need the '^' when you're using re.match (re.search is
>different, in multi line mode).
Perl head in me, I'd rather have it explicitely stated. Whoops, and that
should be a search. Also, the whole reason I have the {1,2} etc. in the regex
is to limit the the number of dice rolled. I know that I could do that in
logic but, again, perl roots, putting nice logic into the regex.
> if not self.compiled_re:
> self.compiled_re = re.compile(r'(\d*)[dD](\d*)([-+]\d+)?$')
> diematch = re.match(self.compiled_re,self.diecode)
Hmmm, good idea, hadn't thought of compiling the re in that manner. Makes
sense, though.
>> if diematch:
>> self.number = int(diematch.group(1) or self.number)
>> self.sides = int(diematch.group(2) or self.sides)
>> self.modifier = int(diematch.group(3) or self.modifier)
>> else:
>> raise BadDieCode
>This part seems quite OK, as do the following remarks.
Yeah, much cleaner that way with the __init__ setting the defaults for the
class. st_dice (standard) is 1, 6, 0 respectively. wod_dice (Worlds of
Darkness) most likely be 1, 10, 0 respectively. Rather nice way to do it.
>You're definitely welcome. And don't worry about your Perl roots
>showing -- so do mine (finetuning RE's is _not_ the average
>Pythonista's hobby:-)
Yeah, I'm kinda embarressed about mine after the flaws were pointed out.
--
Steve C. Lamb | I'm your priest, I'm your shrink, I'm your
ICQ: 5107343 | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------
More information about the Python-list
mailing list