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 / About Run Python Scrip...
Power Automate
Unanswered

About Run Python Script action

(0) ShareShare
ReportReport
Posted on by 262

I have tried several python scripts.

Screenshot 2021-01-27 223033.jpg

The %PythonScriptOutput% is of type text.

I want to make it a number type, but Convert text to number doesn't work.

Screenshot 2021-01-27 223126.jpg
Does anyone have a solution?

SET List TO [155, 168, 5456, 551, 156, 599, 256, 636, 266, 4894, 282, 522, 266]
Text.JoinWithCustomDelimiter List: List CustomDelimiter: $''',''' Result=> JoinedText
System.RunPythonScript PythonCode: $'''listb = [%JoinedText%]
print max(listb)''' ScriptOutput=> PythonScriptOutput ScriptError=> ScriptError
Display.ShowMessage Title: $'''PAD''' Message: $'''%PythonScriptOutput%
%ScriptError%''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True ButtonPressed=> ButtonPressed
Text.ToNumber Text: PythonScriptOutput Number=> TextAsNumber

 

  • ZS440 Profile Picture
    262 on at

    I went into a little more detail.
    Assigning a value to PythonScriptOut using print outputs a newline code.

    Screenshot 2021-01-28 110017.jpg

     

    So I used "sys.stdout.write" in python scrip to avoid outputting the newline code.
    However, I still couldn't convert it to a number.

     

    import sys
    listb = [%JoinedText%].
    m=max(listb)
    sys.stdout.write(str(m))

    Screenshot 2021-01-28 121207.jpg

    In the end, I decided to use regular expressions to extract the numbers.
    This is not a smart way.

    Screenshot 2021-01-28 122257.jpg

     

     

     

    SET List TO [155, 168, 5456, 551, 156, 599, 256, 636, 266, 4894, 282, 522, 266]
    Text.JoinWithCustomDelimiter List: List CustomDelimiter: $''',''' Result=> JoinedText
    System.RunPythonScript PythonCode: $'''import sys
    listb = [%JoinedText%]
    m=max(listb)
    sys.stdout.write(str(m))''' ScriptOutput=> PythonScriptOutput ScriptError=> ScriptError
    Text.RegexParseForFirstOccurrence Text: PythonScriptOutput TextToFind: $'''[0-9]+''' StartingPosition: 0 IgnoreCase: False OccurrencePosition=> Position Match=> Match
    Text.ToNumber Text: Match Number=> TextAsNumber

     

     

    Between the PAD and the Run python script action, I don't think this is a smart way to input/output values.
    Does anyone know of a better way?

  • Henrik_M Profile Picture
    2,021 Super User 2024 Season 1 on at

    Try converting %PythonScriptOutput.Trimmed% since it looks like there is a new line after the text.

  • ZS440 Profile Picture
    262 on at

    Hi Henrik_M
    Thank you for your reply.
    I tried %PythonScriptOutput.Trimmed%.
    But it did not work.

    Screenshot 2021-01-30 020515.jpg

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
11manish Profile Picture

11manish 249 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 202

#3
David_MA Profile Picture

David_MA 180 Super User 2026 Season 2

Last 30 days Overall leaderboard