Re: Checking if elements are empty

2007-09-11 Thread Steve Holden
Neil Cerutti wrote: > On 2007-09-10, Steve Holden <[EMAIL PROTECTED]> wrote: >>> I have a quibble not with the functionality of the boolean check, >>> but with its expressiveness. if y[0] == "" expresses more, i.e., >>> that I expect y[0] to contain a Python byte string. >> I have a quibble with a

Re: Checking if elements are empty

2007-09-11 Thread Steve Holden
Hamilton, William wrote: >> From: Steve Holden >> Neil Cerutti wrote: >>> On 2007-09-10, Chris Mellon <[EMAIL PROTECTED]> wrote: On 9/10/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: > Agreed; but I prefer 'if y[0] == ""', absent more context and > better names. Probably should use

RE: Checking if elements are empty

2007-09-11 Thread Hamilton, William
> From: Steve Holden > Neil Cerutti wrote: > > On 2007-09-10, Chris Mellon <[EMAIL PROTECTED]> wrote: > >> On 9/10/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: > >>> Agreed; but I prefer 'if y[0] == ""', absent more context and > >>> better names. > >> Probably should use u"" if you're going to take

Re: Checking if elements are empty

2007-09-11 Thread Neil Cerutti
On 2007-09-10, Steve Holden <[EMAIL PROTECTED]> wrote: >> I have a quibble not with the functionality of the boolean check, >> but with its expressiveness. if y[0] == "" expresses more, i.e., >> that I expect y[0] to contain a Python byte string. > > I have a quibble with a test that will raise an

Re: Checking if elements are empty

2007-09-11 Thread Wildemar Wildenburger
Steve Holden wrote: > Neil Cerutti wrote: > >>> y = "" > >>> if y[0] == "": > ... print "True" > ... else: > ... print "False" > ... > Traceback (most recent call last): > File "", line 1, in > IndexError: string index out of range > >>> > Uhm, weren't we talking about a list of strings?

Re: Checking if elements are empty

2007-09-11 Thread Piet van Oostrum
> "Chris Mellon" <[EMAIL PROTECTED]> (CM) wrote: >CM> On 9/10/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: >>> Agreed; but I prefer 'if y[0] == ""', absent more context and >>> better names. >CM> Probably should use u"" if you're going to take that route, as this >CM> will fail spuriously if

Re: Checking if elements are empty

2007-09-10 Thread Steve Holden
Neil Cerutti wrote: > On 2007-09-10, Chris Mellon <[EMAIL PROTECTED]> wrote: >> On 9/10/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: >>> Agreed; but I prefer 'if y[0] == ""', absent more context and >>> better names. >> Probably should use u"" if you're going to take that route, as >> this will fail

Re: Checking if elements are empty

2007-09-10 Thread Neil Cerutti
On 2007-09-10, Chris Mellon <[EMAIL PROTECTED]> wrote: > On 9/10/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> Agreed; but I prefer 'if y[0] == ""', absent more context and >> better names. > > Probably should use u"" if you're going to take that route, as > this will fail spuriously if y[0] conta

Re: Checking if elements are empty

2007-09-10 Thread Chris Mellon
On 9/10/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-09-10, Chris Mellon <[EMAIL PROTECTED]> wrote: > > On 9/10/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: > >> On 2007-09-08, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > >> > Lawrence D'Oliveiro wrote: > >> > if y[0]: > >> N

Re: Checking if elements are empty

2007-09-10 Thread Neil Cerutti
On 2007-09-10, Chris Mellon <[EMAIL PROTECTED]> wrote: > On 9/10/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> On 2007-09-08, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: >> > Lawrence D'Oliveiro wrote: >> > if y[0]: >> Not a good idea. >> >>> Why not? >> >> >> >> Because there is a s

Re: Checking if elements are empty

2007-09-10 Thread Chris Mellon
On 9/10/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-09-08, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > > Lawrence D'Oliveiro wrote: > > if y[0]: > Not a good idea. > >>> Why not? > >> > >> Because there is a situation where your version of the test > >> will fail even if t

Re: Checking if elements are empty

2007-09-10 Thread Neil Cerutti
On 2007-09-08, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > Lawrence D'Oliveiro wrote: > if y[0]: Not a good idea. >>> Why not? >> >> Because there is a situation where your version of the test >> will fail even if the first element of y is non-null. > > Such as? Seriously people, a

Re: Checking if elements are empty

2007-09-07 Thread Wildemar Wildenburger
Lawrence D'Oliveiro wrote: if y[0]: >>> Not a good idea. >> Why not? > > Because there is a situation where your version of the test will fail even > if the first element of y is non-null. Such as? Seriously people, a little more verbosity wouldn't hurt here. This isn't a mystery game. /W

Re: Checking if elements are empty

2007-09-07 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Wildemar Wildenburger wrote: > Lawrence D'Oliveiro wrote: > >> In message <[EMAIL PROTECTED]>, Chris >> Mellon wrote: >> >>> On 9/5/07, Steve Holden <[EMAIL PROTECTED]> wrote: Doran, Harold wrote: > > Is there a way to check if the first element of y i

Re: Checking if elements are empty

2007-09-07 Thread Wildemar Wildenburger
Steven D'Aprano wrote: > On Fri, 07 Sep 2007 11:12:05 +0200, Wildemar Wildenburger wrote: > >> Lawrence D'Oliveiro wrote: >>> In message <[EMAIL PROTECTED]>, Chris >>> Mellon wrote: >>> On 9/5/07, Steve Holden <[EMAIL PROTECTED]> wrote: > Doran, Harold wrote: >> Is there a way to chec

Re: Checking if elements are empty

2007-09-07 Thread Steven D'Aprano
On Fri, 07 Sep 2007 11:12:05 +0200, Wildemar Wildenburger wrote: > Lawrence D'Oliveiro wrote: >> In message <[EMAIL PROTECTED]>, Chris >> Mellon wrote: >> >>> On 9/5/07, Steve Holden <[EMAIL PROTECTED]> wrote: Doran, Harold wrote: > Is there a way to check if the first element of y is nu

Re: Checking if elements are empty

2007-09-07 Thread Wildemar Wildenburger
Lawrence D'Oliveiro wrote: > In message <[EMAIL PROTECTED]>, Chris Mellon > wrote: > >> On 9/5/07, Steve Holden <[EMAIL PROTECTED]> wrote: >>> Doran, Harold wrote: Is there a way to check if the first element of y is null? >>> len(y[0]) == 0 >>> >> Better spelled as >> >> if y[0]: > > N

Re: Checking if elements are empty

2007-09-06 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Chris Mellon wrote: > On 9/5/07, Steve Holden <[EMAIL PROTECTED]> wrote: >> Doran, Harold wrote: > >> > >> > Is there a way to check if the first element of y is null? >> > >> >> len(y[0]) == 0 >> >> would be the obvious way, assuming "null" means "the null string"

Re: Checking if elements are empty

2007-09-05 Thread O.R.Senthil Kumaran
> Doran, Harold wrote: > > I presume you meant > > x = ' \t\'ff' > > > > Is there a way to check if the first element of y is null? > > You can use startswith() method of string objects. if x.startswith(' '): print True -- O.R.Senthil Kumaran http://uthcode.sarovar.org -- http:/

Re: Checking if elements are empty

2007-09-05 Thread Daniel Larsson
On 9/5/07, Chris Mellon <[EMAIL PROTECTED]> wrote: > > On 9/5/07, Steve Holden <[EMAIL PROTECTED]> wrote: > > Doran, Harold wrote: > > > > > > > Is there a way to check if the first element of y is null? > > > > > > > len(y[0]) == 0 > > > > would be the obvious way, assuming "null" means "the null

Re: Checking if elements are empty

2007-09-05 Thread Chris Mellon
On 9/5/07, Steve Holden <[EMAIL PROTECTED]> wrote: > Doran, Harold wrote: > > > > Is there a way to check if the first element of y is null? > > > > len(y[0]) == 0 > > would be the obvious way, assuming "null" means "the null string". > Better spelled as if y[0]: -- http://mail.python.org/mailm

Re: Checking if elements are empty

2007-09-05 Thread Steve Holden
Doran, Harold wrote: > Dear list: > > Suppose I have a string as follows > > x = ' \t'ff' > >>> x = ' \t'ff' File "", line 1 x = ' \t'ff' ^ SyntaxError: invalid syntax >>> I presume you meant x = ' \t\'ff' > I can split this up as > > y = x.split('\t') > > Which