← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #210841]: Not able to read from text file when timestamp is used

 

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

    Status: Open => Answered

j proposed the following answer:
Okay as far as I can see, you're doing the following thing:

1. 
for line in f.readlines():
    arr.append(line.strip()) # get rid of newline

Here you read in the file, it is stored in the arr array as string. 
After this, your arr[] looks like this:
["18, 50, 50","19, 25, 56"]

2. 
until[3:6] = (arr[0]) # hour minute second

Here you apply the first element of the array to your time value. 
arr[0] will be a String containing the first line of your file (e.g. "18,50,50"). 
With this line of code, you apply EACH character of this arr[0]-string to the until list. 
After this, your until looks something like [val1,val2,val3,'1','8',',','5','0',','5','0',val10,val11,...].

3. 
timeUntil = time.mktime(tuple(until))

Here you try to make a time out of this list again. This fails because 
a) You replaced 6 elements in the list and replaced them by 8 characters and
b) The characters you inserted are NOT integers which are required by this function.

The easiest solution would be to use the csv(comma separated values)
module:

import csv

reader = csv.reader(open('D:\\DPTT_XML\\Time.txt', "r"), delimiter =
",", skipinitialspace=True)

arr = []

for value in reader:
    arr.append(value)

# later..

until[3:3] = arr[0] # hour minute second  # Notice you probably only
want to replace 3 values, so its [3:3], and you don't need the brackets.

# now this should work:
timeUntil = time.mktime(tuple(until))

I hope this helps

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