[Python-ideas] int()
Cameron Simpson
cs at zip.com.au
Tue Feb 11 22:45:55 CET 2014
On 11Feb2014 19:38, Liam Marsh <liam.marsh.home at gmail.com> wrote:
> do you think it is possible to operate with bytes like with ints?
> useing the fact than
> ord('A')==65 ;
> will it possible to use b'A' like 65 or 00100001, in binary, for example
> for encryption of files, etc...
In Python 2, b'A' makes a str.
In python 3, b'A' makes a bytes object, and array of small (8-bit) ints.
Element 0 of that array _is_ the byte 65, an integer.
So:
Python 3.3.3 (default, Nov 23 2013, 13:21:35)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x=b'A'
>>> x
b'A'
>>> x[0]
65
>>>
Just move to python 3 for your code and you'll be better off for what you
seem to be wanting.
Cheers,
--
Cameron Simpson <cs at zip.com.au>
More computing sins are committed in the name of efficiency (without
necessarily achieving it) than for any other single reason - including
blind stupidity. - W.A. Wulf
More information about the Python-ideas
mailing list