Systemd StandardOutput not working with python script

If you need to define a Systemd service that run a python script and save standard out to a file, you need to be aware of an (for me) unexpected problem. It seemed easy. Using a recent version of systemd, the following setting should output the standard output to the log file.

StandardOutput=append:/path/to/log

It didn't and I used quite some time to debug it. Then I found this answer: Stackoverflow and the solution is to add

Environment="PYTHONUNBUFFERED=1"

to the unit file. This way no output to stdout is buffered. Another way to turn off buffering is to add -u to the python call.

Exec=python -u myscript.py