> To illustrate: > > >>> hex('ABC') > "'\\x41\\x42\\x43'" > >>> print hex('ABC') # This is what I was trying to do today > '\x41\x42\x43' > >>> eval(hex('ABC')) > 'ABC' > > >>> oct('ABC') > "'\\101\\102\\103'" > >>> print oct('ABC') > '\101\102\103' > >>> eval(oct('ABC')) > 'ABC' > > Are there any subtle issues with supporting this that I'm not seeing? This is indeed elegant because it preserves the property that hex() and oct() have for numbers: eval(hex(x)) == x == eval(oct(x)). However, I'm not sure if it should be added. It adds yet another feature to document and support (think of Jython, Pychecker, etc.), and I think that the number of people who care about hexadecimal strings is becoming a vanishingly small fraction of the total number of programmers. (Nobody has cared about octal for a long time; the only use for it at this point is to show unix file permission bits.) And I think that what you really wanted is probably closer to this: >>> import binascii >>> binascii.hexlify('ABC') '414243' >>> --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4