Seite 1 von 1

execPython Python3?

Verfasst: 06 Mär 2023, 16:12
von SirTux
Hi,

Sind die execPython-Sektionen noch aktuell mit Unterstützung von Python 3? Das Beispiel im Handbuch sieht mir arg nach Python3 aus.

Viele Grüße,
Stefan

Re: execPython Python3?

Verfasst: 06 Mär 2023, 16:38
von j.werner
Hallo Stefan,
verwende bitte dafür die verallgemeinerte execWith Sektion:

ExecWith_SECTION PROGRAM PROGRAMPARAS pass PASSPARAS winst WINSTOPTS

Details im Handbuch

Grüße Jan

Re: execPython Python3?

Verfasst: 08 Mär 2023, 12:53
von SirTux
Danke funktioniert. Hier ein Beispiel mit jinja-Templating:

Code: Alles auswählen

execWith_jinja_template "python3"
if not("0" = getLastExitCode)
  Message "failed execWith_jinja_template"
  LogError "failed execWith_jinja_template"
  isFatalError "execWith_jinja_template"
endif

[execWith_jinja_tepmlplate]
import pathlib
from jinja2 import Environment, FileSystemLoader, select_autoescape
env = Environment(loader=FileSystemLoader("%ScriptPath%"))
template = env.get_template("tepmplatename.template")
output = template.render(bla="$bla$", blub="blub")
cfile = pathlib.Path("/path/to/configfile.conf")
cfile.write_text(output)