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:
- What is the best python code generator for my project idea
Most? - 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:
- Python REST with Bottle: https://github.com/telosys-templates-v3/python-web-rest-bottle
- Python persistence using SQL alchemy: https://github.com/telosys-templates-v3/python-persistence-sqlalchemy
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