Hack request: rational numbers
Alex Martelli
aleaxit at yahoo.com
Thu Jan 25 12:18:41 EST 2001
"Pearu Peterson" <pearu at cens.ioc.ee> wrote in message
news:Pine.LNX.4.21.0101251759070.28148-100000 at kev.ioc.ee...
[snip]
> Python. Closest to the above representation I find
>
> 3r/4
>
> that uses similar syntax as in constructing Python complex numbers
> (cf. 3j+4).
What about r('3/4')? Doesn't seem all that far off. Or
r(3)/4. These are easy, and just 2 characters (the parentheses)
away from your dream-syntax.
But there may be something better...
r3/4 would work if your module could have a __getattr__ (and if
you could reserve in your modules all variables of the form 'r\d+'),
as would 3/r4. I suspect you stand a slightly better chance to
get some form of __getattr__ (and __setattr__) into modules, which
would be good for this & other uses, than specialized syntax for
rational numbers -- Moshe Zadka had urged me to write a PEP about
it (though I demurred when I found out that sys.modules CAN at
present house class-instances).
Alex
More information about the Python-list
mailing list