← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #191201]: CSV Reading Name Error....

 

Question #191201 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/191201

    Status: Open => Answered

RaiMan proposed the following answer:
see comments in code:

import csv # not used
# use raw string r"....", no dooble backslash needed
xReader = file(r"C:\Users\davidl01\Desktop\Sikuli-ModelOffice0_Release\newbie.csv")
# xReader.readline() # this reads the first line, and it is not used! delete!
for line in xReader: # this loops through the rest of lines / all the lines
    # should be Ref and Val
    (Ref, Val) = line.strip().split(",")
    # see comment for the "eval" statement
    if (Ref == "Smoker"):
       Settings.Smoker = Val
    if (Ref == "Gender"):
       Settings.Gender = Val
    if (Ref == "Marital"):
       Settings.Marital = Val
    if (Ref == "Forename"):
       Settings.Forename = Val
    if (Ref == "DOB"):
       Settings.DOB = Val
print Settings.Smoker
print Settings.Gender
print Settings.Marital
print Settings.Forename

--- comment on your eval statement

(ref, val) = eval(''.join(('[', line.strip(), ']')))

since you missed the first line, the second one is the first, that is used:
Gender,m

and it produces:
[Gender,m]

so Gender is seen as a variable name (which is not defined), and not as
a string.

If it looked this way, it would work:
["Gender","m"]

but this is not manageable with your code. The apostrophes would have to
be in the csv file.

But the solution is much easier, using your csv file, as you can see above ;-)
 
print Settings.DOB

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.