I want to import one file in main file, but when I try to do that I got an error like below:
[error] Error message: Traceback (most recent call last):
File "C:\DOCUME~1\kartheek.m\LOCALS~1\Temp\sikuli-tmp3883511940798183465.py", line 17, in
import MSTSC_SIM
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\sikuli\SikuliImporter.py", line 45, in load_module
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\sikuli\SikuliImporter.py", line 29, in _load_module
ImportError: Errors in loading sikuli module: MSTSC_SIM
'with' will become a reserved keyword in Python 2.6 (MSTSC_SIM.py, line 62)
How can I fix it? I try adding from sikuli import *
in the module, but I am not able to solve the issue. Below is my code:
#### MSTSC_SIM.sikuli
from sikuli import *
import shutil
import os
def startMstsc(event):
type('r',KeyModifier.WIN)
wait(1)
paste("mstsc")
type(Key.ENTER)
doubleClick(Pattern("RemoteDeskto.png").targetOffset(-79,0))
type(Key.DELETE)
type("simulatorpc1")
click(Pattern("Qptions.png").targetOffset(-26,9))
click(Pattern("GeneralDispl.png").targetOffset(-22,3))
click(Pattern("UISDIGQCClll.png").targetOffset(144,16))
type(Key.ENTER)
alertImg = "Dol.png"
if exists(alertImg):
type(Key.LEFT)
type(Key.ENTER)
wait(5)
else:
wait(7)
doubleClick(Pattern("UsernamePass.png").targetOffset(49,-5))
type(Key.DELETE)
type("simulatoruser")
click(Pattern("IJSBYIIE1ITI.png").targetOffset(52,8))
type("accord_123")
type(Key.ENTER)
wait(3)
click(Pattern("1425987295129.png").targetOffset(-1,29))
wait(3)
click(Pattern("E72startYist.png").targetOffset(1,-23))
click(Pattern("QelpandSuppo.png").targetOffset(-40,26))
wait(2)
type("C:\\Program Files\\Spirent Communications\\SimGEN\\SimGEN.EXE")
wait(1)
type(Key.ENTER)
wait(2)
if not exists("1426049129321.png"):
wait(1)
else:
click(Pattern("ForWindowsap.png").targetOffset(-4,30))
click(Pattern("1425990081814.png").targetOffset(-1,-22))
wait(1)
click(Pattern("EEIE.png").targetOffset(27,-14))
click(Pattern("1425987295129.png").targetOffset(-1,29))
wait(1)
click(Pattern("E72startYist.png").targetOffset(1,-23))
click(Pattern("QelpandSuppo.png").targetOffset(-40,26))
wait(1)
type("C:\\Program Files\\Spirent Communications\\SimGEN\\SimGEN.EXE")
type(Key.ENTER)
wait(2)
click(Pattern("1425988278814.png").targetOffset(6,1))
doubleClick(Pattern("I5AircraFt_E.png").targetOffset(-62,-85))
doubleClick(Pattern("1425989177967.png").targetOffset(-15,2))
click(Pattern("1425990081814.png").targetOffset(-1,-22))
reg_Start = Region(Region(0,15,413,76)).inside()
with reg_Start:
if not exists("lQnmyi.png"):
click(Pattern("ToolsWindowH.png").targetOffset(18,12)) # start the scenario
else:
click(Pattern("ToolsWindowH-start.png").targetOffset(18,12))
wait(2)
click(Pattern("IA414114ENoh.png").targetOffset(-3,42))
wait(2)
dir = os.path.dirname(getBundlePath()) # the folder, where your script is stored
img = capture(SCREEN) # snapshots the screen
shutil.move(img, os.path.join(dir, "running.png")) # to make it persistent
wait(1)
click(Pattern("yil.png").targetOffset(73,6))
click(Pattern("EEndofsimula.png").targetOffset(154,114))
wait(1)
dir = os.path.dirname(getBundlePath()) # the folder, where your script is stored
img = capture(SCREEN) # snapshots the screen
shutil.move(img, os.path.join(dir, "stop.png")) # to make it persistent
wait(2)
#main operation
#startMstsc(1)
#######Main.sikuli
import csv
if ((scnName == "general") & (stpTest == "STP-GPSBL-002")): #checking the condition
print "Done"
import MSTSC_SIM
reload(MSTSC_SIM)
from MSTSC_SIM import *
startMstsc(1)
try:
startApp(1)
onAppear("7Connected.png", handler)
observe(FOREVER)
startTest(1)
stopMstsc(1)
except FindFailed:
popup("image not found")
print "img not found on the screen"
I would appreciate any help to solve my doubt. I want to call the function inside the if condition.
import MSTSC_SIM - show this module. It seems like there something with reserved word "with", which caused that error:
ImportError: Errors in loading sikuli module: MSTSC_SIM
'with' will become a reserved keyword in Python 2.6 (MSTSC_SIM.py, line 62)
Also, tell us, which version of python do you use?
But, just for sure try run this:
with open('testfile.txt', 'w') as f:
f.write('this is just a test')