Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-30 Thread Gabriel Genellina
En Sun, 28 Sep 2008 07:01:12 -0300, Olivier Lauzanne <[EMAIL PROTECTED]> escribió: On Sep 28, 11:21 am, est <[EMAIL PROTECTED]> wrote: Can anyone tell me how to customize a default encoding, let's say 'ansi' which handles range(256) ? I assume you are using python2.5 Edit the file /usr/lib/

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, est wrote: > Well, you succeseded in putting all blame to myself alone. Great. Take it as a hint. > When you guy's are dealing with CJK characters in the future, you'll > find out what I mean. Speaking as somebody who HAS dealt with CJK characters in the past--se

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > from random import randint > ''.join(chr(randint(0, 255)) for i in xrange(len(input))) > > > of course. How else should you get random bytes? :) That a UUOL (Useless Usage Of Len; by analogy to UUOC). This works just

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Christian Heimes
Steven D'Aprano wrote: str(b'123') # b prefix is added "b'123'" Perhaps I'm misinterpreting it, but from here it looks to me that str() is doing what repr() used to do, and I'm really not sure that's a good thing. I would have expected that str(b'123') in Python 3 should do the same thing a

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread est
On Sep 28, 7:12 pm, Lie <[EMAIL PROTECTED]> wrote: > On Sep 28, 3:35 pm, est <[EMAIL PROTECTED]> wrote: > > > > Because that's how ASCII is defined. > > > Because that's how ASCII is defined.  ASCII is a 7-bit code. > > > Then why can't python use another default encoding internally > > range(256)?

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Lie
On Sep 28, 3:35 pm, est <[EMAIL PROTECTED]> wrote: > > Because that's how ASCII is defined. > > Because that's how ASCII is defined.  ASCII is a 7-bit code. > > Then why can't python use another default encoding internally > range(256)? > > > Python refuses to guess and tries the lowest common deno

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread est
On Sep 28, 6:15 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Sun, 28 Sep 2008 01:35:11 -0700, est wrote: > >> Because that's how ASCII is defined. > >> Because that's how ASCII is defined.  ASCII is a 7-bit code. > > > Then why can't python use another default encoding internally >

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Lie
On Sep 28, 4:21 pm, est <[EMAIL PROTECTED]> wrote: > On Sep 28, 4:38 pm, Steven D'Aprano <[EMAIL PROTECTED] > > > > cybersource.com.au> wrote: > > On Sat, 27 Sep 2008 22:37:09 -0700, est wrote: > > str(u'\ue863') > > > Traceback (most recent call last): > > >   File "", line 1, in > > > Unico

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Marc 'BlackJack' Rintsch
On Sun, 28 Sep 2008 01:35:11 -0700, est wrote: >> Because that's how ASCII is defined. >> Because that's how ASCII is defined. ASCII is a 7-bit code. > > Then why can't python use another default encoding internally > range(256)? Because that doesn't suffice. Unicode code points can be >255.

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Olivier Lauzanne
On Sep 28, 11:21 am, est <[EMAIL PROTECTED]> wrote: > On Sep 28, 4:38 pm, Steven D'Aprano <[EMAIL PROTECTED] > Can anyone tell me how to customize a default encoding, let's say > 'ansi' which handles range(256) ? I assume you are using python2.5 Edit the file /usr/lib/python2.5/site.py There is a

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Lie
On Sep 28, 12:37 pm, est <[EMAIL PROTECTED]> wrote: > From python manual > > str( [object]) > > Return a string containing a nicely printable representation of an > object. For strings, this returns the string itself. The difference > with repr(object) is that str(object) does not always attempt to

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread est
On Sep 28, 4:38 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Sat, 27 Sep 2008 22:37:09 -0700, est wrote: > str(u'\ue863') > > Traceback (most recent call last): > >   File "", line 1, in > > UnicodeEncodeError: 'ascii' codec can't encode character u'\ue863' in > > po

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Steven D'Aprano
On Sat, 27 Sep 2008 22:37:09 -0700, est wrote: str(u'\ue863') > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'ascii' codec can't encode character u'\ue863' in > position 0 > : ordinal not in range(128) > > FAIL. What result did you expect? [...] > The

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread est
> Because that's how ASCII is defined. > Because that's how ASCII is defined. ASCII is a 7-bit code. Then why can't python use another default encoding internally range(256)? > Python refuses to guess and tries the lowest common denominator -- ASCII -- > instead. That's the problem. ASCII is I

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Steven D'Aprano
On Sun, 28 Sep 2008 03:55:46 -0400, Terry Reedy wrote: > est wrote: >>>From python manual >> >> str( [object]) >> >> Return a string containing a nicely printable representation of an >> object. For strings, this returns the string itself. The difference >> with repr(object) is that str(object)

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Steven D'Aprano
On Sun, 28 Sep 2008 19:03:42 +1300, Lawrence D'Oliveiro wrote: > In message > <[EMAIL PROTECTED]>, est > wrote: > >> The problem is, why the f**k set ASCII encoding to range(128) > > Because that's how ASCII is defined. > >> while str() is internally byte array it should be handled in

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-28 Thread Terry Reedy
est wrote: >>From python manual > > str( [object]) > > Return a string containing a nicely printable representation of an > object. For strings, this returns the string itself. The difference > with repr(object) is that str(object) does not always attempt to > return a string that is acceptable t

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-27 Thread Marc 'BlackJack' Rintsch
On Sat, 27 Sep 2008 22:37:09 -0700, est wrote: > The problem is, why the f**k set ASCII encoding to range(128) Because that's how ASCII is defined. ASCII is a 7-bit code. > while str() is internally byte array it should be handled in range(256) > !! Yes `str` can handle that,

Re: str() should convert ANY object to a string without EXCEPTIONS !

2008-09-27 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, est wrote: > The problem is, why the f**k set ASCII encoding to range(128) Because that's how ASCII is defined. > while str() is internally byte array it should be handled in > range(256) !! But that's for random bytes. How would you convert an a

str() should convert ANY object to a string without EXCEPTIONS !

2008-09-27 Thread est
>From python manual str( [object]) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that str(object) does not always attempt to return a string that is acceptable to eval(); its goal is to r