List Manipulation

Bruno Desthuilliers onurb at xiludom.gro
Tue Jul 4 13:09:02 EDT 2006


Roman wrote:
(please dont top-post - corrected)
> 
> Steven D'Aprano wrote:
> 
>>On Tue, 04 Jul 2006 07:01:55 -0700, Roman wrote:
>>
>>
(snip)
>>
>>>cnt = 0
>>>p=[]
>>>reader = csv.reader(file("f:\webserver\inp.txt"), dialect="excel",
>>>                         quotechar="'", delimiter='\t')
>>>for line in reader:
>>>    if cnt > 6:
>>>       break
>>
>>That's a very unPythonic way of doing the job. The usual way of doing
>>this would be something like this:
>>
>>for line in reader[:7]:
>>    # no need for the "if cnt > 6: break" clause now
>>
> I am getting
>
> TypeError: unsubscriptable object
>
> when specifying
>
> for line in reader[:7]:
>

Should have been :

for line in list(reader)[:7]:
  # code here


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list