Forum Discussion

aafreen_jamadar's avatar
aafreen_jamadar
Occasional Contributor
2 years ago

Python Classes and objects

Why Can't I run a script with a python class in it? It only seems to work with recorded scripts and methods.

 

5 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Here's an example,

    def myfunc():
        x = 3
        class MyClass(object):
            y = x
            def myMethod():
                Log.Message("myMethod")
        return MyClass
    
    def main():
        Log.Message(myfunc())
        Log.Message(myfunc().y)
        Log.Message(myfunc().myMethod())
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Can you provide a code example and corresponding error?

     

  • aafreen_jamadar's avatar
    aafreen_jamadar
    Occasional Contributor

    Hi, I've written a script with a class and functions That I am trying to access using the object of the class. There is no error but the button to run the code is disabled.

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

       

      Again, can you provide code sample?

      Only parameterless functions/procedures can be executed using Run button.

      Classes cannot be executed themselves but must be instantiated/called from regular functions.

       

  • aafreen_jamadar's avatar
    aafreen_jamadar
    Occasional Contributor

    def Test():

                    class Light():

    lightManager = Aliases.PD2000i.HwndSource_MainWindow.MainWindow.MainLightManager

    def white():

                    light Manager.Click(164, 68)

                    aqObject.CheckProperty(lightManager.FloodWhiteTitle, “WPFControlText”, cmpEqual, “White”)

                    lightManager.Click(137,728)

                    lightManager.Click(137,728)

    def dif_white():

                                    aqObject.CheckProperty(lightManager.DiffusedFloodWhiteTitle, “WPFControlText”, cmpEqual, “Diffused White”)

                                    lightManager.Click(160,794)

                                    lightManager.Click(160,794)

                    obj = Light()

                    def iteration():

                                    obj.white()

                                    obj.dif_white()

     

     

    How do I instantiate this from a regular function?