cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ZS440
Resolver II
Resolver II

About Run Python Script action

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

 

3 REPLIES 3
ZS440
Resolver II
Resolver II

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
Dual Super User
Dual Super User

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

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

Screenshot 2021-01-30 020515.jpg

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power automate tips 768x460 v2.png

Restore a Deleted Flow

Did you know that you could restore a deleted flow? Check out this helpful article.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (1,832)