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

Description changed to:
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".

May somebody points me where I am wrong please?

Thanks!

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

_______________________________________________
Mailing list: https://launchpad.net/~sikuli-driver
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp

Reply via email to