Dynamic Python




Dynamic Python


Author: Jerry Chae



Description

The Dynamic Python plugin takes a Python script and runs it. Additionally, when the Python script has any 3rd party Python modules integrated, the plugin automatically downloads and installs them in the local virtual environment for PAM. You can pass on parameters to the Python script as well. This plug in requires Python coding skills.


WARNING!


Use Dynamic Python carefully

Dynamic Python alters the virtual environment file without going through PAM’s VENV Manager features. This may result in some infrequent case where a potential resource conflict may be observed when PAM tries to run another Automation Scenario with the virtual environment. When this happens, no error messages will be displayed. PAM just cannot run any Automation Scenarios anymore.

If you encounter a case like above, please just delete the virtual environment file at:

%userprofile%\.argos-rpa.venv 

The virtual environment file has a file name with date-time like “20210402-165006”.


WARNING!


Create requirements.txt carefully

Dynamic Python may overwrite versions of the same library used by another plugin.

Therefore, scenarios may not run properly if destructive changes have been made in different versions.
(e.g. numpy1.0x and numpy2.0x, etc.)


When creating requirements.txt, you should check what libraries are being used by other plug-ins and which version they are.

The version of the library can be checked from the scenario execution log.


NOTE

Creating Python files using Curly Braces


In DynamicPython, when a variable is used from a plugin, write r“{some_val}” in the file.
Therefore, if you use Curly Braces in other parts of the file, it may be misidentified as a variable, resulting in an error as the number of variables has not been read correctly.
There are two ways to avoid this error.
1. Read variables from an external file.
2. Not to use curly braces outside of the variable part of the code.

As an example, the main types of curly braces in Python are as follows
・Format function :
'His name is {}'.format(name)
・dict :
dict = {“a” : “Apple”, “b” : “Banana”}



Need help?

Technical contact to tech@argos-labs.com


May you search all operations,





Input (Required)


Python script file, usually a text file with extension .py (see example below.)


Input (Optional)


Req Text

requirements.txt file is the standard text file that lists the 3rd party Python modules that the main Python script will be calling for.

https://pip.pypa.io/en/stable/user_guide/#requirements-files


Parameters

Parameters are defined in the main Python script (see example). You can pass on parameters by using the notation ::= as in Python


Encoding option

If the input file uses any other encoding options than UTF-8, you can specify it here.



Output


Return Value

This plugin does not return any values


Return Code

        0 for success

        9 for failure



How to set parameters








Example of files


Python script


file name = Dynamic Python-3.402.913


import glob
import os
import pandas as pd
from pandas import ExcelWriter
from openpyxl import load_workbook

wdir = r"{wdir}"
in_files = (
    os.path.join(wdir, '1.xlsx'),
    os.path.join(wdir, '2.xlsx'),
    os.path.join(wdir, '3.xlsx'),
)
out_file = os.path.join(wdir, 'task2.xlsx')
writer = ExcelWriter(out_file, engine='openpyxl')
num_rows = 0
for filename in in_files:
    excel_file = pd.ExcelFile(filename)
    (_, f_name) = os.path.split(filename)
    (f_short_name, _) = os.path.splitext(f_name)
    for sheet_name in excel_file.sheet_names:
        df_excel = pd.read_excel(filename)
        df_excel.to_excel(writer,index=False,header=False,startrow=num_rows+1)
        num_rows += df_excel.shape[0]
writer.save()
print(os.path.abspath(out_file), end='')





File name = Dynamic Python-3.402.913


# requirements.txt for pandas handling

openpyxl
pandas





Update 2022.02.08





All Plugins