Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in RPA by (5.3k points)
edited by

Here is an image showing Python scope activity (version 3.6 and target x64):

Python Scope

image

The main problem is the relation between both invoke python methods, the first one is used to start the class object, and the second one to access a method of that class. Here is an image of the first invoke python properties:

Invoke Python init method

image

And the getNumberPlusOne activity call:

Invoke Python getNumberPlusOne method

image

The python code being executed:

class ExampleClass: def __init__(self,t,n): self.text = t self.number = n def getNumberPlusOne(self): return (self.number+1)

And finally, the error when executing the second Invoke Python Method:

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: System.InvalidOperationException: Error invoking Python method ----> System.Runtime.Serialization.InvalidDataContractException: Type 'UiPath.Python.PythonObject' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.

Any idea about where is the mistake and how to interact with the output object created in the init method?

1 Answer

0 votes
by (9.5k points)

here is the Load Python Script activity: invoke python script

In my case the local variable "pyScript" is a pointer to the python object, i.e. an instance of ExampleClass.

Now, there is the Invoke Python Method activity but methods on the class are inaccessible to UiPath -you can't just type pyScript.MethodName(). invoke python method

use another method outside your class in order to access or manipulate your object:

class ExampleClass:
    def __init__(self,t,n):
        self.text = t
        self.number = n

    def getNumberPlusOne(self):
        return (self.number+1)


foo = ExampleClass("bar", 42)

def get_number_plus_one():
    return foo.getNumberPlusOne()

enter image description here

Related questions

0 votes
1 answer
asked Jul 10, 2019 in RPA by Abhishek_31 (12.7k points)
0 votes
1 answer
asked Jul 9, 2019 in RPA by Abhishek_31 (12.7k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 13, 2019 in RPA by Abhishek_31 (12.7k points)

Browse Categories

...