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?

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_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,190)