Language change and code breaks

"Jürgen A. Erhard" juergen.erhard at
Thu Jul 12 15:06:50 EDT 2001

>>>>> "Bjorn" == Bjorn Pettersen <BPettersen at> writes:

    >> From: "Jürgen A. Erhard" [mailto:juergen.erhard at]
    Bjorn> [snip]

    >> I had a script recently where I wanted to pass in a command
    >> line param that could be a numeric ratio, like

    >> thescript --ratio=1/3

    >> [...]

    Bjorn> If you're eval'ing random strings the user types in you
    Bjorn> really deserve whatever you get <1/3 wink>.

Oops, you're right... though there's no security hole in there if the
script only runs *as that user*.  And I generally trust the users of
these scripts anyway (= I trust myself ;-)

    >>>> r = '1/3'
    >>>> import re
    >>>> tmp = r.split('/')
    >>>> assert len(tmp) == 2
    >>>> a, b = tmp
    >>>> assert re.match(r'[0-9]+', a) != None
    >>>> assert re.match(r'[0-9]+', b) != None
    >>>> x, y = map(int, [a,b])
    >>>> ratio = (x + 0.0) / y
    >>>> ratio
    Bjorn> 0.33333333333333331

    Bjorn> Nothing magic about it...

And nothing readable. ;-}

Bye, J

 Jürgen A. Erhard  (juergen.erhard at, jae at
          My WebHome:
   Stop the execution of Mumia Abu-Jamal!  (
         I have a firm grip on reality, now I can strangle it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 248 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list