user2502794
user2502794

Reputation: 137

Using Power Automate, how do you read a "Flow variable" into a Python Script

Using Microsoft Power Automate Desktop (PAD), I have captured a moderately long string called ExtractPDFText. I can display the text in a message window, now I need it to run through Python Script.

In the Power Automate Desktop application's python input box I am just trying to get it to run this:

x = str(%ExtractedPDFText%)
print("work")

But it keeps returning an "unexpected token"

enter image description here

How should I be reading this variable? I tried with and without the str() function.

Upvotes: 1

Views: 3134

Answers (3)

Andy Brown
Andy Brown

Reputation: 5522

Here is a fleshed out answer - thanks to the comment from user2502794. Start by writing a Python script which works in Python:

enter image description here

This just returns all the strings in a list which contain the letter "s".

Now in Power Automate Desktop, set the value of a test variable:

enter image description here

Add a Python script action:

enter image description here

You could now display the value of the output, as captured in the PAD variable:

enter image description here

This would give this for our example:

enter image description here

What I can't do is work out how to return a list, rather than string representation of a list. I suspect the answer is that I now have to remove the square brackets and use a PAD Split text action, but this seems clunky, but I'm excited to be able to do all my text processing in Python now (watching PAD looping over the items in a list wasn't that exciting ...).

Upvotes: 0

Diarox Carbon
Diarox Carbon

Reputation: 25

yes, the sol is triple quotes - """ %value% """

Upvotes: -1

Cazzym Hawkins
Cazzym Hawkins

Reputation: 303

Try wrapping in the string in quotation marks

Upvotes: 1

Related Questions