- Visão geral
- Criptografia
- Banco de Dados
- Java
- Python
- WebAPI
Atividades do desenvolvedor
O exemplo a seguir explica como executar automaticamente um código do Python criado no runtime e escrever um log de arquivo. Apresenta atividades como Python Scope e Run Python Script. Você pode encontrar essas atividades no pacote UiPath.Python.Activities.
Before running any Python workflow, make sure that you have Python3 installed.
É assim que um processo de automação pode ser construído:
-
Abra o Studio e crie um Processo.
-
Arraste um contêiner Sequência para o Designer de Fluxo de Trabalho.
-
Crie um novo argumento:
Argument name Direction Tipo de Argumento Valor Padrão in_PythonPathEm String Adicione o caminho da pasta onde o Python foi instalado -
Drag an If activity inside the Sequence container.
- Adicione a expressão
String.IsNullOrEmpty(in_PythonPath) orelse not Directory.Exists(in_PythonPath)no campo Condição.
- Adicione a expressão
-
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. - Adicione a expressão
"Pyhon Path not configured. Please configure path by setting the argument 'in_PythonPath'."no campo Texto.
- In the Properties panel, add the expression
-
Arraste uma atividade Terminate Workflow após a atividade Message Box.
- In the Properties panel, add the expression
"Input Arguments not correct"in the Reason field.
- In the Properties panel, add the expression
-
Arraste uma atividade Python Scope após a atividade If.
- 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:
-
Execute o processo. A automação executa o código Python e grava um log em um arquivo denominado
logs.txt.