Python not that wierd

Steve Lamb grey at despair.rpglink.com
Wed Aug 2 11:13:56 EDT 2000


On Wed, 2 Aug 2000 10:12:47 +0200, Alex Martelli <alex at magenta.com> wrote:
>And one of _my_ core values is 'do things once and once only'...:-).

    Right, which is why I switched it to search, not match, in the code.

>You do want to match the RE even when not at the beginning of the
>string?  Then the ^ is wrong.  It's only useful when you want to match
>a *start-of-line* in multiline mode (but you're not running your RE in
>multiline mode, it seems to me?).

    No, that is exactly how I want it.  xdy+z on a line by itself, start of
the line, no trailing spaces, nothing.  

>OK, but the {1,2} (or, since it can be 0, should actually be {0,2}) can
>only limit the *number of DIGITS* in the number-of-dice-to-roll.  How
>comes all limits fall at  99 or 999?  Seems a strange coincidence to
>me.  but OK, whatever.

    Easiest way to limit it.  99d999+/-99 seemed reasonable to exceed most
people's expectations.  I've yet, in my years of gaming, to ever see the need
to roll more than 12 dice, anything higher than 100 sides, or a modifier to
ever exceed 3 times the sides on the die.  So instead of picking some
arbitrary number like, oh, 50, I just limited the number of places to
something reasonable.

   You're right, though, I should have tried {0,2} first.  I will try that
when I next work on it.  Right now I am tackling the problem of defining the
valid rulesets and how to go about actually running the correct ruleset
without requiring ifs for each set.  I want to have a directory with rulesets
in the keys and the class name in the variable then just have dice assigned
to the class.  However, I'm not sure if I can do something like ${$foo}() in
Python.  Haven't research yet.

>    def thefun(self):
>        diematch=self.re.match(self.diecode)
>        # etc etc

    Heh, let me read in the code I used...


class st_dice:
  def __init__(self):
    if (not self.re):
      self.re = re.compile(r'^(?:(\d{1,2})|)[Dd](?:(\d{1,3})|)(?:([+-]\d{1,2})|)$')

   def parse_diecode(self):
    diematch = self.re.search(self.diecode)
[snip rest of code]

    I latched onto the self.foo stuff quite early.  Really enjoyed it once I
got the concept down.

>Agreed.  And a derived class could also tweak the re if a certain game
>should need a slightly different syntax (if you use it as self.re).

    Yup, though if there is such an RPG out there I am not aware of it.  ;)

-- 
         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