UiPath Documentation
activities
latest
false
Important :
Veuillez noter que ce contenu a été localisé en partie à l’aide de la traduction automatique. La localisation du contenu nouvellement publié peut prendre 1 à 2 semaines avant d’être disponible.

Activités du développeur.

Gérer des scripts Python

L’exemple suivant explique comment exécuter automatiquement un code Python créé au moment du runtime et écrire un journal de fichier. Il contient des activités telles que Étendue Python (Python Scope) et Exécuter le script Python (Run Python Script). Vous pouvez retrouver ces activités dans le package UiPath.Python.Activities.

Remarque :

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

Voici comment le processus d'automatisation peut être créé :

  1. Ouvrez Studio et démarrez un nouveau Processus.

  2. Faites glisser un conteneur Séquence vers le concepteur de workflow.

  3. Créez un nouvel argument :

    Argument nameDirectionTypes d'argumentsValeur par défaut
    in_PythonPathdansChaîne de caractères (string)Ajouter le chemin du dossier dans lequel Python a été installé
  4. Drag an If activity inside the Sequence container.

    • Ajoutez l’expression String.IsNullOrEmpty(in_PythonPath) orelse not Directory.Exists(in_PythonPath) dans le champ Condition.
  5. Faites glisser un conteneur Sequence dans le champ Alors (Then) de l'activité Si (If).

  6. Drag a Message Box activity inside the Sequence container.

    • In the Properties panel, add the expression "Error" in the Caption field.
    • Ajoutez l’expression "Pyhon Path not configured. Please configure path by setting the argument 'in_PythonPath'." dans le champ Texte.
  7. Faites glisser une activité Terminer le workflow (Terminate Workflow) après l’activité Zone de message (Message Box).

    • In the Properties panel, add the expression "Input Arguments not correct" in the Reason field.
  8. Faites glisser une activité Étendue Python (Python Scope) après l’activité Si (If).

    • 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. Exécutez le processus. L'automatisation exécute le code Python et écrit un journal dans un fichier nommé logs.txt.

Cette page vous a-t-elle été utile ?

Connecter

Besoin d'aide ? Assistance

Vous souhaitez apprendre ? UiPath Academy

Vous avez des questions ? UiPath Forum

Rester à jour