Language change and code breaks

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


>>>>> "Bjorn" == Bjorn Pettersen <BPettersen at NAREX.com> writes:

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

    >> I had a script recently where I wanted to pass in a command
    >> line param that could be a numeric ratio, s.th. 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 gmx.net, jae at users.sourceforge.net)
          My WebHome: http://members.tripod.com/Juergen_Erhard
   Stop the execution of Mumia Abu-Jamal!  (http://www.freemumia.org)
         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: <http://mail.python.org/pipermail/python-list/attachments/20010712/f1420341/attachment.sig>


More information about the Python-list mailing list