python - 生成带有参数的 Python 模板

标签 python code-generation

我之前使用 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 是最受欢迎的之一。但我想知道在做出决定之前我是否正朝着正确的方向前进。

所以我的问题是:

  1. 最适合我的项目想法的 python 代码生成器是什么 最多?
  2. 我应该为这样的项目构建网络界面吗? 使用 Python 平台,还是其他类似 PHP 的平台?

最佳答案

如果您只想从模型生成 Python 代码,您可以尝试 Telosys 代码生成器:http://www.telosys.org/ .

它允许为包括 Python 在内的不同类型的语言生成代码。

在您的情况下,我建议创建一个基本的 DSL 模型(或从此处下载 DSL 模型示例 http://www.telosys.org/download/models-v3/)并使用以下 Python 模板:

Telosys 的“CLI”版本可能是最佳选择(因为它独立于任何 IDE):https://github.com/telosys-tools-bricks/telosys-cli/wiki

关于python - 生成带有参数的 Python 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48812380/

相关文章:

javascript - 启用 CORS 的正确位置在哪里?

Python随机数字字母和附加生成器

Python图像失真

c++ - 在 C++ 宏中输出反斜杠

code-generation - 是否可以添加使用 CodeFluent 实体片段?

python - 无法使用 pyenv 切换 Python

c++ - 几个具有不同签名的虚拟成员函数

Matlab Codgen eig() 函数 - 奇怪的行为

c - 有没有适合替代C宏的推荐代码生成方式?

c# - 在进行 visual studio 自动化时,是否有更好的方法来处理 RPC_E_CALL_REJECTED 异常?