To fetch data in sikuli from CSV file

Asked by Anurag

i already write the script using images and all, and in this i am fetching data from csv file. and it working fine for data only in one coloumn. now i have to expand it so that it take data from other coloumns also.
out = open("c:\\temp1\\et.csv","rb")
data = csv.reader(out)

        data=[row[1] for row in data]
print(data[0]) and all

so please help me how can do this

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Eugene S (shragovich) said :
#1

Hi,

The csv reader will work like this:

import csv

input = open('fileName.csv', 'rb')

for row in csv.reader(input):
    firstColumnValue = row[0]
    secondColumnValue = row[1]
    thirdColumnValue = row[2]

Cheers,
Eugene

Revision history for this message
Anurag (annubhav10) said :
#2

Thanks for reverting me Eugene,But my problem is :

say my csv is like this :
name, anurag , rajeev, bhaskar, rhonda
age, 23,24,25,28
marks, 23, 45,67,76

Now i have to call each name , age, and marks at their specific location in script respectively and then i have to repeat the same for others left.
through my script i was able to call up data of coloumn 1 individually and i used it perfectly as per their requirement and script workinf fyn.

hope you got my question !!!

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Everything is available in comment #2
+ some basic Python knowledge.

rows = []
for row in csv.reader(input):
    rows.append(row)

now in rows you have your lines split into the values.

for row in rows:
    for value in rows:
        print value,
    print

this should show the content of your csv

row[1][2] is the age of rajeev

BTW: if the structure of the csv is your own decision, this would be easier to work through:

name, age, marks
anurag, 23, 23
rajeev, 24, 45
bhaskar, 25, 67
rhonda, 28, 76

Revision history for this message
Anurag (annubhav10) said :
#4

out = open("c:\\temp1\\et.csv","rb")
data = csv.reader(out)

        data=[row[1] for row in data]
print(data[0])
print(data[1])
print(data[2])

Now i have to call row value like anurag from name , 23 age and 23 from marks individually like 'anurag' at specific location in script and i am able to do so easliy by calling data[0], data[1], data[2]
but now i have to call rajeev, 24, 45 and use in script at same location where i used the value of first ones.

means i have to repeat steps of my script after the successful completion using values of row 1(anurag,23,23 at their respective location like anurag at their location and 23 at their and 23 at their) and then it use value of row 2 and then row 3

hope you got my question !!!

Revision history for this message
Anurag (annubhav10) said :
#5

i am totally agree with u Raiman but my query is that what i mentioned above.

Revision history for this message
RaiMan (raimund-hocke) said :
#6

again: all said in comment #3

Can you help with this problem?

Provide an answer of your own, or ask Anurag for more information if necessary.

To post a message you must log in.