[Python] simplest jinja2 template loading for one-file python script

Discussão em 'Python' iniciado por Stack, Agosto 6, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using Python only for simple scripts and every time I look into Python packaging, there is a new standard or technologie.

    Now when I develop a small one-file tool and want to load a jinja2 template, I don't know how.

    I could use FileSystemLoader and somehow build a path relative to the currently executed python file. This works in my git checkout during development.

    But what if I also want to package my script? Than I should probably use PackageLoader. But is there some magic variable that gives me the package name of current python file?

    Could anybody provide a snippet that just works and maybe does not even need a lot of boilerplate?

    Continue reading...

Compartilhe esta Página