Result getting printed as UiPath.Python.PythonObject

Hi Team,

i am trying to invoke a method from python and print the result in UiPath but instead of result the following is getting as following: UiPath.Python.PythonObject

can anyone help what exactly needs to be fixed

Hello Sai,

  1. Convert Python Object to String: Modify your Python code to explicitly convert the result into a string before returning it. This ensures that UiPath receives a simple data type that it can print directly.

Code : # Original Python code returning some object
def your_python_function():
result = some_operation()
return result

Modified Python code converting result to string before returning

def your_python_function():
result = some_operation()
result_str = str(result)
return result_str
In this modified code, result is converted to a string using the str() function before it is returned. This ensures that the output of your Python function is a string data type, which UiPath can handle for printing.

Replace some_operation() with the actual code that produces the result you want to convert to a string.

Once you’ve made this modification to your Python code, you can invoke this function from UiPath, and the result will be a string that you can print or manipulate as needed within your UiPath workflow.

Also Please check :

  1. UiPath Python Scope: Ensure that you’re using the correct Python scope activity in UiPath to execute your Python code. Different Python activities in UiPath might handle Python objects differently, so try using different activities or configurations to see if they provide more useful output.

Thank you
Please let me if your issue resolve.
Happy automation.

i changed something like this, but still same error… in python i am able to print the result, but not getting result in UiPath

image

Hi @devasaiprasad_K ,

Use “Get Python Object” Activity: This activity is used to get the .NET data type from a Python object. It can only be used inside the Python Scope activity.

Refer to my attached test workflow. I hope this helps you.
Main.xaml (9.4 KB)

Python code:

import sys

def add_numbers(num1, num2):
    return num1 + num2

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: python script.py <num1> <num2>")
    else:
        try:
            num1 = float(sys.argv[1])
            num2 = float(sys.argv[2])
            result = add_numbers(num1, num2)
            print("The sum is", result)
        except ValueError:
            print("Invalid input. Please provide valid numbers.")

image

image

Regards,
Vinit Mhatre