Re: [Tutor] simple unicode question

2014-08-27 Thread Alan Gauld
On 27/08/14 15:57, Albert-Jan Roskam wrote: if *fewer* than 1 in 10 operations will raise an exception, then use try...except; but if *more* than 1 in 10 operations will raise an exception, and it is safe to do so, then LBYL may be appropriate. Thanks a lot, Steven! This kind of stuff should

Re: [Tutor] simple unicode question

2014-08-27 Thread Albert-Jan Roskam
- Original Message - > From: Steven D'Aprano > To: tutor@python.org > Cc: > Sent: Tuesday, August 26, 2014 2:08 PM > Subject: Re: [Tutor] simple unicode question > > On Tue, Aug 26, 2014 at 03:58:17AM -0700, Albert-Jan Roskam wrote: > >> Interesting,

Re: [Tutor] simple unicode question

2014-08-26 Thread Steven D'Aprano
On Tue, Aug 26, 2014 at 03:58:17AM -0700, Albert-Jan Roskam wrote: > Interesting, you follow a "look before you leap" approach here, > whereas `they` always say it is easier to ”ask forgiveness than > permission” in python. Anyone who says it is *ALWAYS* easier is lying or confused :-) It is

Re: [Tutor] simple unicode question

2014-08-26 Thread Albert-Jan Roskam
- Original Message - > From: Danny Yoo > To: Albert-Jan Roskam > Cc: Python Tutor Mailing List > Sent: Saturday, August 23, 2014 2:53 AM > Subject: Re: [Tutor] simple unicode question > > On Fri, Aug 22, 2014 at 2:10 PM, Albert-Jan Roskam > wrote: >>  H

Re: [Tutor] simple unicode question

2014-08-22 Thread Steven D'Aprano
On Fri, Aug 22, 2014 at 02:10:21PM -0700, Albert-Jan Roskam wrote: > Hi, > > I have data that is either floats or byte strings in utf-8. I need to > cast both to unicode strings. I am probably missing something simple, > but.. in the code below, under "float", why does [B] throw an error > but

Re: [Tutor] simple unicode question

2014-08-22 Thread Ben Finney
Danny Yoo writes: > Hi Albert, > > Just following up: I consider the 2 (or 3) arg form of unicode() to be > a design flaw in the Standard Library. It's redundant because the > bytes type already has a decode() method: > > https://docs.python.org/3/library/stdtypes.html#bytes.decode > > > So

Re: [Tutor] simple unicode question

2014-08-22 Thread Danny Yoo
Hi Albert, Just following up: I consider the 2 (or 3) arg form of unicode() to be a design flaw in the Standard Library. It's redundant because the bytes type already has a decode() method: https://docs.python.org/3/library/stdtypes.html#bytes.decode So I would personally write convert() l

Re: [Tutor] simple unicode question

2014-08-22 Thread Danny Yoo
On Fri, Aug 22, 2014 at 2:10 PM, Albert-Jan Roskam wrote: > Hi, > > I have data that is either floats or byte strings in utf-8. I need to cast > both to unicode strings. Just to be sure, I'm parsing the problem statement above as: data :== float | utf-8-encoded-byte-string

Re: [Tutor] simple unicode question

2014-08-22 Thread Dave Angel
Albert-Jan Roskam Wrote in message: > Hi, > > I have data that is either floats or byte strings in utf-8. I need to cast > both to unicode strings. I am probably missing something simple, but.. in the > code below, under "float", why does [B] throw an error but [A] does not? > >.. >>>

[Tutor] simple unicode question

2014-08-22 Thread Albert-Jan Roskam
Hi, I have data that is either floats or byte strings in utf-8. I need to cast both to unicode strings. I am probably missing something simple, but.. in the code below, under "float", why does [B] throw an error but [A] does not? # Python 2.7.3 (default, Feb 27 2014, 19:39:10) [GCC 4.7.2] on l