Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34224 > unrolled thread
| Started by | Anatoli Hristov <tolidtm@gmail.com> |
|---|---|
| First post | 2012-12-04 14:02 +0100 |
| Last post | 2012-12-04 15:38 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: CSV out of range Anatoli Hristov <tolidtm@gmail.com> - 2012-12-04 14:02 +0100
Re: CSV out of range Neil Cerutti <neilc@norwich.edu> - 2012-12-04 13:58 +0000
Re: CSV out of range Anatoli Hristov <tolidtm@gmail.com> - 2012-12-04 15:38 +0100
| From | Anatoli Hristov <tolidtm@gmail.com> |
|---|---|
| Date | 2012-12-04 14:02 +0100 |
| Subject | Re: CSV out of range |
| Message-ID | <mailman.460.1354626169.29569.python-list@python.org> |
The issue is now solved I did:
for x in mylist:
try:
sku.append(x[4])
except IndexError:
pass
Thank you for your help
Anatoli
[toc] | [next] | [standalone]
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Date | 2012-12-04 13:58 +0000 |
| Message-ID | <ai6dsiFk3vkU5@mid.individual.net> |
| In reply to | #34224 |
On 2012-12-04, Anatoli Hristov <tolidtm@gmail.com> wrote:
> The issue is now solved I did:
>
> for x in mylist:
> try:
> sku.append(x[4])
> except IndexError:
> pass
>
> Thank you for your help
Optionally:
for x in mylist:
if len(x) >= 4:
sku.append(x[4])
But do you really need to save the whole file in a list first?
You could simply do:
for record in csvreader:
if len(record) >= 4:
sku.append(record[4])
Or even:
sku = [record[4] for record in csvreader if len(record) >= 4]
--
Neil Cerutti
[toc] | [prev] | [next] | [standalone]
| From | Anatoli Hristov <tolidtm@gmail.com> |
|---|---|
| Date | 2012-12-04 15:38 +0100 |
| Message-ID | <mailman.463.1354631894.29569.python-list@python.org> |
| In reply to | #34227 |
On Tue, Dec 4, 2012 at 2:58 PM, Neil Cerutti <neilc@norwich.edu> wrote: > On 2012-12-04, Anatoli Hristov <tolidtm@gmail.com> wrote: >> The issue is now solved I did: >> >> for x in mylist: >> try: >> sku.append(x[4]) >> except IndexError: >> pass >> >> Thank you for your help > > Optionally: > > for x in mylist: > if len(x) >= 4: > sku.append(x[4]) > > But do you really need to save the whole file in a list first? > You could simply do: > > for record in csvreader: > if len(record) >= 4: > sku.append(record[4]) > > Or even: > > sku = [record[4] for record in csvreader if len(record) >= 4] > > -- > Neil Cerutti Thanks Neil, I'm still testing it - just trying to clean the things out and be sure that I can do all of the stuff :) I will create a list only of the products I have in the DB and will compare them for prices stock etc... so the list will be smaller :) Thanks again Anatoli
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web