- Información general
- Criptografía
- Base de datos
- Java
- Python
- WebAPI
Actividades de desarrollador
El siguiente ejemplo explica cómo ejecutar automáticamente un código Python creado en runtime y escribir un registro de archivo. Presenta actividades como Ámbito de Python y Ejecutar script Python. Puedes encontrar estas actividades en el paquete UiPath.Python.Activities.
Before running any Python workflow, make sure that you have Python3 installed.
Así es como se puede construir el proceso de automatización:
-
Abre Studio y crea un nuevo Proceso.
-
Arrastra un contenedor Secuencia al Diseñador de flujo de trabajo.
-
Crear un nuevo argumento:
Nombre de Argumento Dirección Tipo de argumento Valor predeterminado in_PythonPathEn Cadena Agregue la ruta de la carpeta donde se ha instalado Python -
Drag an If activity inside the Sequence container.
- Añada la expresión
String.IsNullOrEmpty(in_PythonPath) orelse not Directory.Exists(in_PythonPath)en el campo Condición.
- Añada la expresión
-
Drag a Sequence container in the Then field of the If activity.
-
Drag a Message Box activity inside the Sequence container.
- In the Properties panel, add the expression
"Error"in the Caption field. - Añada la expresión
"Pyhon Path not configured. Please configure path by setting the argument 'in_PythonPath'."en el campo Texto.
- In the Properties panel, add the expression
-
Arrastra una actividad Terminar flujo de trabajo después de la actividad Cuadro de mensaje.
- In the Properties panel, add the expression
"Input Arguments not correct"in the Reason field.
- In the Properties panel, add the expression
-
Arrastra una actividad Ámbito de Python después de la actividad Si.
- In the Properties panel, add the argument
in_PythonPathin the Path field. - Select your Python version from the Version drop-down list (Python_36 in this example).
- In the Properties panel, add the argument
-
Drag a Run Python Script activity inside the Python Scope container.
- In the Properties panel, add the following code snippet in the Code field:
String.Format( "import sys" + Environment.NewLine _ + "import os " + Environment.NewLine _ + "with open('{0}\logs.txt', 'w') as f: " + Environment.NewLine _ + " f.write('Starting script! \n')" + Environment.NewLine _ + " f.write('Computing!\n')" + Environment.NewLine _ + " f.write('Finishing script! \n')" + Environment.NewLine, _ Directory.GetCurrentDirectory.Replace("\", "\\"))String.Format( "import sys" + Environment.NewLine _ + "import os " + Environment.NewLine _ + "with open('{0}\logs.txt', 'w') as f: " + Environment.NewLine _ + " f.write('Starting script! \n')" + Environment.NewLine _ + " f.write('Computing!\n')" + Environment.NewLine _ + " f.write('Finishing script! \n')" + Environment.NewLine, _ Directory.GetCurrentDirectory.Replace("\", "\\"))
- In the Properties panel, add the following code snippet in the Code field:
-
Ejecuta el proceso. La automatización ejecuta el código Python y escribe un registro en un archivo llamado
logs.txt.