PEP0238 lament

Duncan Booth duncan at NOSPAMrcp.co.uk
Tue Jul 24 09:20:25 EDT 2001


Roy Smith <roy at panix.com> wrote in
news:roy-24160D.07405224072001 at news1.panix.com: 

> Duncan Grisby <dgrisby at uk.research.att.com> wrote:
> 
>> So what can I do?  I can't even do something ugly like
>> 
>>   if sys.hexversion > 0x2000200:
>>       c = a // b
>>   else:
>>       c = a / b
>> 
>> since the a // b gives a syntax error.
> 
> I'm almost embarassed to suggest this, but what about:
> 
>    if sys.hexversion > 0x2000200:
>        c = eval ("a // b")
>    else:
>        c = a / b
> 
Or you could do c = divmod(a, b)[0]

which should lightly trip off the tongue for any version :(


-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list