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

Community site session details

Session Id : vAgzb9NedVLNglH/2VVun5
Power Automate - Power Automate Desktop
Answered

Python Script in PAD Outputting

Like (0) ShareShare
ReportReport
Posted on 10 Jul 2023 18:20:15 by 21

Hi , I am trying to output the below script to a premade variable, The point of the script is to add a random integer between 1-20 to said variable. I know this is a very basic script but my issue is getting it to output in PAD. Its not that the script is wrong as I have checked in IDLE etc. 

 

Script in use:

 

import random

# Generate a random integer between 1 and 20
random_number = random.randint(1, 20)

# Define a variable
my_variable = int("""%FlightTime%""")

# Add the random number to the variable
my_variable += random_number

print(my_variable)

 

Flow:

Chick_0-1689013167984.png

Any assistance would be appreciated

  • Chick Profile Picture
    21 on 11 Jul 2023 at 10:16:24
    Re: Python Script in PAD Outputting

    Thanks again Agnius that worked perfectly, and Thanks Michael to 🙂

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on 11 Jul 2023 at 06:02:57
    Re: Python Script in PAD Outputting

    To add to what @MichaelAnnis said - PAD uses Python 2.0. It does not support later versions of Python. It does install some modules automatically with the PAD package. So, it is not really always necessary to point to the path

    where the modules are stored.

     

    You can enable the %ScriptError% variable to make it easier to debug the issue. It is disabled by default, but you can enable it here:

    Agnius_0-1689055056234.png

     

    I've just tested it and in fact it doesn't find a module named 'random'.

    Agnius_3-1689055319753.png

     

    That's why it doesn't output anything. Otherwise your script would be fine. It works fine with another sample script I had at hand that uses the module 'datetime' that comes pre-installed with PAD.

     

    In this case you would in fact need to provide a path to where Python modules are stored (outside of the PAD installation path) in your local system.

    In my case that's C:\Users\agnius\AppData\Local\Programs\Python\Python38-32\Lib

    Agnius_1-1689055254961.png

     

    However, since I've got Python 3.8 installed on my system (as you can probably tell from the name of the folder), the random module does not work with PAD at all. It throws a syntax error. 

    Agnius_2-1689055286050.png

    So, if you want to run a Python script in PAD that requires a Python module that does not come pre-installed with PAD, you would need to install Python 2 on your system and then target the modules library in the Module folder path field.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution.
    If you like my response, please give it a Thumbs Up.

    If you are interested in Power Automate, you might want to follow me on LinkedIn at https://www.linkedin.com/in/agnius-bartninkas/

     

  • MichaelAnnis Profile Picture
    5,721 Moderator on 10 Jul 2023 at 20:49:57
    Re: Python Script in PAD Outputting

    Under Advanced, point the folder where import module lies.  They python code in PAD needs that path to access those modules

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 2