which is more 'pythonic' / 'better' ?

Steve Holden steve at holdenweb.com
Mon Sep 12 11:29:33 EDT 2005


Will McGugan wrote:
> Pierre Barbier de Reuille wrote:
> 
> 
>>>I would actualy use the following for this particular case..
>>>
>>>text = line[n:n+1] or 'nothing'
>>
>>
>>... and you would get either a list of one element or a string ...
>>I think you wanted to write :
>>
>>text = (line[n:n+1] or ['nothing'])[0]
> 
> 
> I was assuming that 'line' would be a string, not a list. Seems more 
> likely give the name and context.
> 
I'd say it's much more likely that line is a list of lines, since it 
seems improbable that absence of a character should cause a value of 
"nothing" to be required.

so-i-say-po-tay-to-ly y'rs  - steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/




More information about the Python-list mailing list