我之前使用 JET 和 Eclipse 从模型生成 Java 文件。我是 Python 的新手,我正在寻找一种基于从用户读取的参数(数据)自动生成 python 模块的方法 - 用于教育目的。
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.
经过研究,我发现那里有很多 python 生成器,我猜 Jinja 是最受欢迎的之一。但我想知道在做出决定之前我是否正朝着正确的方向前进。
所以我的问题是:
- 最适合我的项目想法的 python 代码生成器是什么 最多?
- 我应该为这样的项目构建网络界面吗? 使用 Python 平台,还是其他类似 PHP 的平台?
最佳答案
如果您只想从模型生成 Python 代码,您可以尝试 Telosys 代码生成器:http://www.telosys.org/ .
它允许为包括 Python 在内的不同类型的语言生成代码。
在您的情况下,我建议创建一个基本的 DSL 模型(或从此处下载 DSL 模型示例 http://www.telosys.org/download/models-v3/)并使用以下 Python 模板:
- 带 Bottle 的 Python REST:https://github.com/telosys-templates-v3/python-web-rest-bottle
- 使用 SQL 炼金术的 Python 持久性:https://github.com/telosys-templates-v3/python-persistence-sqlalchemy
Telosys 的“CLI”版本可能是最佳选择(因为它独立于任何 IDE):https://github.com/telosys-tools-bricks/telosys-cli/wiki
关于python - 生成带有参数的 Python 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48812380/