Few things

Nick Coghlan ncoghlan at email.com
Fri Nov 26 05:40:02 EST 2004


Josiah Carlson wrote:
>>A command like this:
>>print 0x9f, 054135
>>This prints an hex and octal. I think the syntax for the hex is a bit
>>ugly; and the syntax for the octal looks just dangerous (and wrong) to
>>me.
> 
> 
> Internally those values are Python integers, there would need to be a
> special way to tag integers as being originally hex or octal.  Or the
> pyc would need to store the fact that it was originally one of those
> other methods specifically for the print statement.

I believe the OP was objecting to the spelling of "this integer literal is hex" 
and "this integer literal is octal".

Python stole these spellings directly from C. Saying it's ugly without 
suggesting an alternative isn't likely to result in developers taking any 
action, though. (Not that that is particularly likely on this point, regardless)

If the spelling really bothers the OP, the following works:

   print int("9f", 16), int("54135", 8)

That's harder to type, is a lot slower at run-time and uses more memory, though.

Cheers,
Nick.



More information about the Python-list mailing list