UiPath Documentation
activities
latest
false
Importante :
Este contenido se ha localizado parcialmente a partir de un sistema de traducción automática. La localización de contenidos recién publicados puede tardar entre una y dos semanas en estar disponible.

Actividades de desarrollador

Administrar scripts de Python

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.

Nota:

Before running any Python workflow, make sure that you have Python3 installed.

Así es como se puede construir el proceso de automatización:

  1. Abre Studio y crea un nuevo Proceso.

  2. Arrastra un contenedor Secuencia al Diseñador de flujo de trabajo.

  3. Crear un nuevo argumento:

    Nombre de ArgumentoDirecciónTipo de argumentoValor predeterminado
    in_PythonPathEnCadenaAgregue la ruta de la carpeta donde se ha instalado Python
  4. 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.
  5. Drag a Sequence container in the Then field of the If activity.

  6. 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.
  7. 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.
  8. Arrastra una actividad Ámbito de Python después de la actividad Si.

    • In the Properties panel, add the argument in_PythonPath in the Path field.
    • Select your Python version from the Version drop-down list (Python_36 in this example).
  9. 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("\", "\\"))
      
  10. Ejecuta el proceso. La automatización ejecuta el código Python y escribe un registro en un archivo llamado logs.txt.

¿Te ha resultado útil esta página?

Conectar

¿Necesita ayuda? Soporte

¿Quiere aprender? UiPath Academy

¿Tiene alguna pregunta? Foro de UiPath

Manténgase actualizado