Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am reading a csv data and some of the row may have 5 cells and some of them may have 6. I want to check if a particular row has 5 cell or 6?

I am using python.

What I have tried:

Below is my code so far:

while _i<_len:
			if str(_data[_i][2]).lower().strip() == 'xxxx':
				_summary = str(_data[_i][1]).lower() + ' - '+ str(_data[_i][0]).lower()
			if str(_data[_i][5]).strip() in ("",None):
				_description = 'Anything: '+str(_data[_i][0]).lower()+'\n ABC: '+str(_data[_i][1]).lower()+'\n DEF: '+str(_data[_i][2]).lower()+'\n GHI: '+str(_data[_i][3]).lower()+'\n Category: '+str(_data[_i][4]).lower()'''


The part where I am checking if certain cell is empty is working and throwing index out of bound error if row only has 5 cells.
Posted
Updated 15-Mar-16 20:02pm
v2

1 solution

Found the solution.

Figured out its a nested list (a list within list). I was able to use len to identify the length of the sublist and then process it further.

Thanks you.
 
Share this answer
 
Comments
Patrice T 16-Mar-16 7:11am    
Use Accept answer to close the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900