sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #15933
[Question #221131]: "with" statement
New question #221131 on Sikuli:
https://answers.launchpad.net/sikuli/+question/221131
Hi,
I am trying to use the "with" statement in Sikuli (in Caller.sikuli file) with a class I have created (in TheClass.sikuli file). But I fail to do it. My goal is to be able to close the instanced object when the end of the "with" statement is reached. Here is an example of my code:
The code:
*******************************************
# In TheClass.sikuli:
# The instanced class.
class MyClass():
def __init__(self):
self.aProperty = "I am a property." # a property for testing.
return
# The class manager which returns the MyClass object.
class ClassManager():
def __init__(self):
self.myClass = MyClass()
return
def __enter__(self):
return self.myClass
def __exit__(self, type, value, traceback):
self.myClass.aProperty = "I am a different property."
self.myClass = None # Try to destroy the object with None.
return
# In Caller.sikuli:
from sikuli import *
from TheClass import *
if __name__ == '__main__':
with ClassManager() as aNewClass:
print aNewClass.aProperty
print aNewClass.aProperty # Should make an error since aNewClass should be None.
*******************************************
The output is:
"I am a property."
"I am a different property."
This means that "aNewClass" is still instanced since I should get an error at the second "print aNewClass.aProperty". In "def __exit__(self, type, value, traceback)" I am not able to use the function close() which seems to be overwrote by the Region.close() of Sikuli.
May somebody points me where I fail please?
Thanks!
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.