Mini-tut: getting started with Python

Second installment: Providing code in the UiPath Expression Editor, and not from a script.

(First, see @ronanpeter’s solution for plenty more information.)

The only difference between this workflow and the previous one is where we put the python code. In this version, everything is basically the same, but the code goes here:

loadcod-code-properties

This by itself doesn’t tell you much, but take a look at what’s in the expression editor:

So you can paste the python code in if you like, here it is:

"
f = open('C:\\Users\\Winter\\Documents\\UiPath\\InvokePython\\helloworld.txt', 'w')
f.write('Hello World from UiPath running Python. Using Code input instead of File.')
f.close()
"

Notice that you can use a multiline string now. In the past you might have had to write something like this:

"f = open('C:\\Users\\Winter\\Documents\\UiPath\\InvokePython\\helloworld.txt', 'w')" + Environment.NewLine + "f.write('Hello World from UiPath running Python. Using Code input instead of File.')" + Environment.NewLine + "f.close()" + Environment.NewLine + ""

What a pain to code! Oh well, you don’t have to do it any more.

I’ve quite wrongly assumed here that you’d be using a VB.Net based workflow. You may prefer C# and by using that for your processes. If you are using C#, this next screenshot may well be superfluous for you, but in case you’re just getting started with C# too, here it is:
LoadCode-Code-CSharp

As you can see, the only real difference is the “@” preceding the multiline string. Here’s the code in case you want to paste it in:

@"
f = open('C:\\Users\\Winter\\Documents\\UiPath\\InvokePython\\helloworld.txt', 'w')
f.write('Hello World from UiPath running Python. This is a C-sharp process.')
f.close()
"

I hope this is of some use to you.
Best regards,
burque505

1 Like