web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Accessing Automate var...
Power Automate
Answered

Accessing Automate variables from Python script

(0) ShareShare
ReportReport
Posted on by 5

I have an Automate variable named inputText. I would like to perform some work on that text inside a "Run a Python Script" action and return the result.

 

How do I refer to the inputText variable from my Python code?

How do I return the modified string back to Automate?

 

I can't find any documentation that explains how this is supposed to work. Any pointers/suggestions would be appreciated.

 

(I'm running on Windows 11 (no Azure) if that matters)

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @ThomT 

    Please find the below sample python use case for addition two numbers

    Deenuji_0-1711643997716.png

     

     

    Code:

     

    SET number1 TO 10
    SET number2 TO 5
    SET AdditionResult TO $'''%''%'''
    @@copilotGeneratedAction: 'False'
    Scripting.RunPythonScript PythonCode: $'''def add(a, b):
     return a + b
    
    def subtract(a, b):
     return a - b
    
    def multiply(a, b):
     return a * b
    
    def divide(a, b):
     if b == 0:
     return \"Error: Division by zero!\"
     return a / b
    
    # Sample usage:
    num1 = %number1%
    num2 = %number2%
    
    AdditionResult=add(num1, num2)
    print(AdditionResult)
    ''' ScriptOutput=> AdditionResult ScriptError=> ScriptError

     

     

    How to copy/paste above suggested code into your PAD?

    Deenuji_1-1711644151848.gif

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀. If you'd like to appreciate me, please write a LinkedIn recommendation 🙏

  • Verified answer
    CU16071609-1 Profile Picture
    6,255 Moderator on at

    @ThomT 

    Another Example with string operation.

    Deenuji_0-1711645826431.png

    Python code:

    Deenuji_1-1711645901949.png

     

     

    Only python code what I have written inside python action [Not full PAD code]:

    # Assuming inputText is already defined somewhere in your code
    inputText = "%Input_Text%"
    
    # Function definition
    def modify_text(inputText):
     # Modify the inputText as needed
     modified_text = inputText.upper() # Example: Convert inputText to uppercase
     return modified_text
    
    # Call the function with inputText as argument
    modified_text = modify_text(inputText)
    
    # Return the modified text back to Automate
    print(modified_text) # You can print it or handle it in any other appropriate way for Automate


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀. If you'd like to appreciate me, please write a LinkedIn recommendation 🙏

  • ThomT Profile Picture
    5 on at

    Thank you SO much. This is the part I was missing:

    inputText = "%Input_Text%"

     I didn't know that a string bracketed by % characters would access a variable name defined outside of the Python script action.

     

    I'd still love to know where this information is in the PAD docs.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 289

#2
11manish Profile Picture

11manish 288 Super User 2026 Season 2

#3
Henil Profile Picture

Henil 125

Last 30 days Overall leaderboard