How to read a row one by one in the for loop

Asked by manisha

Hello,
I want to use the For Loop and print a row one by one whatever i required.
here is my code:

import csv
with open("details.csv") as csvFile:
    reader = csv.DictReader(csvFile)
    for row in reader:
        #print(row['Name'], row['age'], row['DOB'])
        if['age'] == '21':
            print(row['Name'], row['age'], row['DOB'])
        else:
            continue

Here i want run the for loop until 6 times and also i want specific data of who ever age is '21', that person details only i want print, if it is other than '21' then skip the row. but my code is doesn't perform exactly like i want.
can anyone help me..?
Thank you :)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Kartheek
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

   if row['age'] == '21':

Revision history for this message
Best Kartheek (mkreddy083) said :
#2

I tried your code and your file and got an error. Then I replaced tabs in your csv file with commas and capitalized "dob" to "DOB":
of course i changed your code as @Raiman said like that,

now your output is :
('Arun', '21', '01/08/93')
('nani', '21', '04/05/93')

Revision history for this message
manisha (manishareddy1111) said :
#3

Thanks Kartheek, that solved my question.

Revision history for this message
manisha (manishareddy1111) said :
#4

Thank you Raiman