Python – Generate Python templates with parameters

Generate Python templates with parameters… here is a solution to the problem.

Generate Python templates with parameters

I previously used JET and Eclipse to generate Java files from models. I’m new to Python and I’m looking for a way to automatically generate python modules based on parameters (data) read from the user – for educational purposes.

For example, a student will be guided to a webpage, where he/she enters the name of a project, select different control statements (ie.a while loop), enter a boolean expression, and the loop body , and hit generate. The webpage will generate a .py module for him/her that could be used for educational purposes.

After researching, I found out that there are a lot of python generators out there, and I guess Jinja is one of the most popular. But I wonder if I’m moving in the right direction before making a decision.

So my question is:

  1. What is the best python code generator for my project idea
    Most?
  2. Should I build a web interface for such a project?
    Use the Python platform, or other platforms like PHP?

Solution

If you just want to generate Python code from a model, you can try the Telosys code generator: http://www.telosys.org/

It allows code generation for different types of languages, including Python.

In your case, I recommend creating a basic DSL model (or downloading a DSL model example from here http://www.telosys.org/download/models-v3/) and use the following Python template:

The “CLI” version of Telosys is probably the best choice (because it is independent of any IDE): https://github.com/telosys-tools-bricks/telosys-cli/wiki

Related Problems and Solutions