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 y[0] contains a unicode

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 stdin, line 1, in module IndexError: string index out of range Uhm, weren't we talking about a list of strings? /W --

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 exception

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 that route, as this

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 u if you're going to take that

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 test that will

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 little more verbosity

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 the first element of y is

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 situation where your version of the

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]: Not a good idea. Why not?

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] contains a unicode

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 spuriously if y[0]

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 check if the first element of y is

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 null? len(y[0]) == 0

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]: Not a good idea. Why not? /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 is null? len(y[0]) == 0

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-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. Better spelled as

Checking if elements are empty

2007-09-05 Thread Doran, Harold
Dear list: Suppose I have a string as follows x = ' \t'ff' I can split this up as y = x.split('\t') Which gives [ ' ', 'ff'] len(y) 2 Is there a way to check if the first element of y is null? -- http://mail.python.org/mailman/listinfo/python-list

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 stdin, 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 gives [ '

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]: --

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 string. Better spelled

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 --