Do I need to prepare for the Python-Training?

Category:
Scripting
Answer

The DIgSILENT “Scripting with Python in PowerFactory” focusses mainly on the communication between PowerFactory and Python. The training includes a short introduction to the Python language and syntax. However, knowing the basics in advance will enable the participant to focus more on the main tasks and the objectives of the exercises. Therefore, we recommend basic scripting experience (in Python), even though it not mandatory for the participation in this training. If you have already skills in other scripting languages like MATLAB, the adaptation to Python is usually no problem.

DIgSILENT recommends that the participant is familiar with the following topics:

  • Data Types:
    • The types integer, float, string and list will be used (dictionaries are part of additional exercises)
  • Mathematical operations:
    • Usage of Python as a calculator
  • String operations:
    • String replacement as well as the combination of strings with “+”
    • Usage of escape characters like \t or\n
    • String formatting and usage of placeholders (%s, %i, %f)
  • if conditions:
    • Including “elif” (else if) and “else”
    • Logical connections with “and” and “or”
  • List operations:
    • append(), extend(), sort(), range(), len() min(), max(), sum(),…
    • Multi-dimensional lists
  • Loops:
    • “for” and “while” loops
    • Usage of break and continue
  • Functions:
    • Understanding of the basic principle of functions

 

The “PythonExamples.py” file contains little examples of code for the above mentioned points. In order to execute a Python script, a Python interpreter has to be installed on your computer. The interpreter can be downloaded from the official Python homepage. More information about the installation of a Python Interpreter are also available in the PowerFactory User Manual, Section “Installation of a Python Interpreter”.

If you want to prepare yourself for the training, you can do the following exercise. You will find a possible solution in “SolutionExampleExercise.py”.

Example exercise:

  • Iterate through a list with values from 0 to 100 and print out only the even numbers. If the number is a multiple of 7, print a message like: “14 is a multiple of 7”

Write the uneven numbers (except the multiples of 7) into a new list. Calculate the average value of the list and print it rounded to 4 decimals.

If you want to do some further preparations, there are many basic Python tutorials available online. However, the basics shown in this FAQ are sufficient to participate in our “Scripting with Python in PowerFactory” training.

Back