← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #142609]: readline.read_history_file is unavailable with sikuli?

 

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

    Status: Answered => Solved

Tet Yoon LEE confirmed that the question is solved:
Thank for your help although I think I may not have explained what I'm
trying to do very well.

The reason I am reading from a file is I have a long list of URLs
(500+). I want to visit these URLs one by one doing stuff inbetween
visiting each one. It seems easiest to read them from a file. The file
only contains the list of URLs. However sometimes I may want to do
something else on the computer and stop the script for a while. I may
even want to restart the computer or whatever.

I guess I can manually record the current state of the script but that
seems a bit unnecessary so I was planning to get the Sikuli script to
automatically record the last position it was reading and use that
position upon start up. I have another script which does everything else
I want which I designed earlier and I added the readline stuff it works
as expected except for the history.

I think readline is one way to do what I'm doing at least from
http://docs.python.org/tutorial/inputoutput.html although you may be
right I'm not understanding the history function properly. I believe
line and linecache are other methods but I couldn't work out how to get
line working as I wanted at all (didn't try very hard) and linecache
isn't provided by Sikuli I think.

Anyway, although line number seemed the easier way to do what I'm
trying, perhaps it's best to just save the line to a history file and
then when the script starts load the line from the history file and
readline until I reach the right line. This is what I've implemented now
and it seems to work.

listfile=open(file_dir + "list.txt")
historyfileread = file(file_dir + "historyfile.txt")
historyread = historyfileread.readline()
historyfileread.close()
while True:
	if historyread == "":
		break
	lineread = listfile.readline()
	if lineread == historyread:
		break


Later in my script it will start with the next line (it does readline again). So no need to import anything and it all works well. Again, my coding and methods may seem exceptionally amateurish because that's what I am but I'm not planning to release it so if it works I'm happy :-) (You may notice this script doesn't currently handle the absence of a history file.) 

Thanks again, of course even though I've found one way if you do have
any other suggestions, I'm still listening.

Cheers

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