sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #11246
Re: [Question #132445]: Reading / writing to a file in sikuli
Question #132445 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/132445
Alex Nilsson posted a new comment:
The write to file feature in sikuli seems to be a little buggy, I tried
to make my script put different stuff in a log txt file. (To start out
with, I just had sikuli open a notepad and paste the text i needed in,
but that's a little clumsy.. :-))
The first time it worked ok, but the text only appeared about half the time thereafter, I played around with it and sometimes the text
came after a minute, but after the script itself was done running...And sometimes nothing at all got written to the file..
Tried creating a new file, with a new name every time my_file=file(my_dir + filename + ".txt", "w") and appending to an existing my_file=file(my_dir + "mynewfile.txt", "a"), but nothing worked consistently..
The text file itself was in use, (even after the script stopped..) I
killed the program and that freed the logfile, so I'm guessing the
file.close or the my_file.write doesn't work as advertised..
Anyhows, I made a workaround for windows and made an account here to
share it with you guys, hoping to give a bit back to the community,
since several of, especially RaiMans, answers and examples ( Thank you!
:-) ) has helped me out quite a bit.
import datetime #To get a random filename for each logfile, I use the
time in the filename itself..
<My script runs here and could for instance set the variables app = "Office 2010 install" and pcnavn = "xppcname23bn1t">
#log
logSti = "C:\\Documents and Settings\\local user\\Desktop\\addInsSekuli\\logs\\" #define the path to ones logfiles
logFilNavn = datetime.datetime.now().strftime(app + "@" + pcnavn + "@" + "%H%M%S.txt") #sets the filename
sisse_log=file(logSti + logFilNavn, "w") #create the file
sisse_log.close # close the file/handles to the file.
The result is a file named:
Office 2010 install@xppcname23bn1t@xxxxxxxxxx
where 121716 is the current time, for example 12:17:16.
(You can include %d%m%y in the file if you want date, month and year in
the name, to make an unique filename, though I prefer just the time,
since no user orders the same software )
Now instead of having one big logfile, you have many small ones in a
dir, so you can sort 'em directly in windows explorer, by name or date
modified.. :-)
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.