Re: chr(i) ASCII under Python 3

2010-04-27 Thread Antoine Pitrou
Le Mon, 26 Apr 2010 22:26:28 +0200, Alf P. Steinbach a écrit :
 On 26.04.2010 22:12, * Dodo:
 Hi all,
 Under python 2.6, chr() Return a string of one character whose ASCII
 code is the integer i. (quoted from docs.python.org) Under python 3.1,
 chr() Return the string of one character whose Unicode codepoint is
 the integer i.

 I want to convert a ASCII code back to a character under python 3, not
 Unicode.

 How can I do that?
 
 Just use chr().

Or, if you want a bytes object, just use the bytes constructor:

 bytes([65])
b'A'

Regards

Antoine.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: chr(i) ASCII under Python 3

2010-04-27 Thread Dave Angel

Dodo wrote:

Hi all,
Under python 2.6, chr() Return a string of one character whose ASCII 
code is the integer i. (quoted from docs.python.org)
Under python 3.1, chr() Return the string of one character whose 
Unicode codepoint is the integer i.


I want to convert a ASCII code back to a character under python 3, not 
Unicode.


How can I do that?

Dorian


Like a lot of things, it depends on why you're asking what you are.

Characters are in Unicode on Python 3.x, by definition.  That's not a 
problem, it's a feature.  Such a character is 16 bits, and if it's an 
ASCII value, the bottom 7 bits exactly match ASCII, and the remaining 
ones are zero.


However, sometimes you don't really want strings of characters, you want 
an array of 8 bit values, and you're used to the equivalence that 
earlier versions of Python give you.  In those cases, sometimes a string 
(Unicode) works transparently, and sometimes you really want a byte 
array.  Simplest example is when you're calling a DLL written in another 
language.


The types bytes and bytearray are considered sequences of integers (each 
of range 0 to 255), rather than characters.  And there are ways to 
convert back and forth between those and real strings.


DaveA



--
http://mail.python.org/mailman/listinfo/python-list


chr(i) ASCII under Python 3

2010-04-26 Thread Dodo

Hi all,
Under python 2.6, chr() Return a string of one character whose ASCII 
code is the integer i. (quoted from docs.python.org)
Under python 3.1, chr() Return the string of one character whose 
Unicode codepoint is the integer i.


I want to convert a ASCII code back to a character under python 3, not 
Unicode.


How can I do that?

Dorian
--
http://mail.python.org/mailman/listinfo/python-list


Re: chr(i) ASCII under Python 3

2010-04-26 Thread Alf P. Steinbach

On 26.04.2010 22:12, * Dodo:

Hi all,
Under python 2.6, chr() Return a string of one character whose ASCII
code is the integer i. (quoted from docs.python.org)
Under python 3.1, chr() Return the string of one character whose
Unicode codepoint is the integer i.

I want to convert a ASCII code back to a character under python 3, not
Unicode.

How can I do that?


Just use chr().

ASCII (7-bit) is a subset of ISO Latin-1 (7-bit), which is a subset of Unicode's 
Basic Multilingual Plane (BMP, original Unicode, 16-bit) which is a subset of 
Unicode (21-bit).



Cheers  hth.,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: chr(i) ASCII under Python 3

2010-04-26 Thread Dodo

Le 26/04/2010 22:26, Alf P. Steinbach a écrit :

On 26.04.2010 22:12, * Dodo:

Hi all,
Under python 2.6, chr() Return a string of one character whose ASCII
code is the integer i. (quoted from docs.python.org)
Under python 3.1, chr() Return the string of one character whose
Unicode codepoint is the integer i.

I want to convert a ASCII code back to a character under python 3, not
Unicode.

How can I do that?


Just use chr().

ASCII (7-bit) is a subset of ISO Latin-1 (7-bit), which is a subset of
Unicode's Basic Multilingual Plane (BMP, original Unicode, 16-bit) which
is a subset of Unicode (21-bit).


Cheers  hth.,

- Alf


Oh, I see... thanks

* just realize the problem doesn't come from here *
--
http://mail.python.org/mailman/listinfo/python-list


Re: chr(i) ASCII under Python 3

2010-04-26 Thread Alf P. Steinbach

On 26.04.2010 22:26, * Dodo:

Le 26/04/2010 22:26, Alf P. Steinbach a écrit :

On 26.04.2010 22:12, * Dodo:

Hi all,
Under python 2.6, chr() Return a string of one character whose ASCII
code is the integer i. (quoted from docs.python.org)
Under python 3.1, chr() Return the string of one character whose
Unicode codepoint is the integer i.

I want to convert a ASCII code back to a character under python 3, not
Unicode.

How can I do that?


Just use chr().

ASCII (7-bit) is a subset of ISO Latin-1 (7-bit), which is a subset of
Unicode's Basic Multilingual Plane (BMP, original Unicode, 16-bit) which
is a subset of Unicode (21-bit).


Cheers  hth.,

- Alf


Oh, I see... thanks

* just realize the problem doesn't come from here *


Uhm, I meant to write that ISO Latin-1 is 8-bit. Sorry. Keyboard gremlin.


Cheers,

- Alf

--
http://mail.python.org/mailman/listinfo/python-list