← Back to team overview

sikuli-driver team mailing list archive

[Question #211380]: Not able to close the text file when array is used.

 

New question #211380 on Sikuli:
https://answers.launchpad.net/sikuli/+question/211380

Hi, 

I want to write the text file when I have used array.
It was giving me error as :
 my_file.close() 
NameError: name 'my_file' is not defined

==============================================

Check the code:
# Game ended
def Employee(event):
    wait(1)
    click("FEmployeeCod-9.png")
    wait(1)
    type(event.region.currentTimeEntry)
    wait(1)
    el = "\n" # the end of line you want to use
    my_file=file("D:\DPTT_XML\DPWrite.txt", "w")
    if exists ("ULUNPAID-7.png"):
        type("UL")
        my_file.write("UL"+el) # if you want to have line breaks
        wait(2)
    if exists ("WOWEEKLYOFF-7.png"):
        type("WO")
        my_file.write("WO"+el) # if you want to have line breaks
        wait(2)
    wait(1)
# Main function
# Go to Portal for checking Employee Attendance report
import array
DPRead=[]
f=open("D:\\DPTT_XML\\DPRead.txt","r")
fout = open("D:\\DPTT_XML\\DPRead-results.txt","w")

for line in f.readlines():
    DPRead.append(line.strip()) # get rid of newline
f.close()
wait(2)
click("1348813496420-5.png")
wait(5)
click("earthprogram-5.png")
type("firefox" + Key.ENTER)
wait(5)
type("t", KeyModifier.CTRL)
wait(10)
type("https://localhost:9080/index.action"; + Key.ENTER)
wait("LoginUsernam-5.png",20)
click("Username-5.png")
type("ABCD")
click("Password-5.png")
type("1234")
wait(2)
#   Employee code for E1 : abhileft1
wait(2)
SCREEN.currentTimeEntry = DPRead[2]
onAppear("FEmployeeCod-9.png", Employee)
observe(50)
wait(1)
#   Employee code for E1 : abhileft2
click("VEmployeeCod.png")
wait(2)
SCREEN.currentTimeEntry = DPRead[3]
onAppear("FEmployeeCod-9.png", Employee)
observe(50)
my_file.close()    # ERROR OCCURS AT THIS STAGE
wait(2)
App.close("Firefox")
wait(3)


Please do needful help.


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