python - python文件是否可以编写另一个python文件?
问题描述
我正在为 python 创建一个工作表制作器。我可以让 python 创建另一个 .py 文件并写入它吗?
class ws:
def _init_(self, number, ctype):
self.number=wsno
self.ctype=plang
x=input('Questions file:')
y=open(x, mode='r')
z=f.read()
a,b,c,d,e=z.split(';')
wsno=input('Worksheet number: ')
wspl=input('Language: ')
title=wspl+" Worksheet "+wsno
q1="1: "+ws.a
q2="2: "+ws.b
q3="3: "+ws.c
q4="4: "+ws.d
q5="5: "+ws.e
def renderws():
renderws()
是我想让 python 文件生成另一个 python 文件的地方。提前致谢!
解决方案
这绝对有效:
>>> import os
>>> with open( 'test.py', 'w' ) as fout :
... fout.write( 'print "hello, python"' )
...
>>> os.system( 'python test.py' )
hello, python
0
>>>
推荐阅读
- android - 在 Redmi Note7 的 camera2 API Android 中捕获图像时相机冻结
- apache-spark - 如何使用流数据帧进行 rdd 转换
- php - 如何从 Google API PHP 客户端获取 SMTP 凭据
- excel - 什么循环条件可以让代码连续运行
- android - 在编译 Kotlin 代码之前从 gradle 运行 CMake
- reactjs - 解析错误:意外的令牌,应为“{”
- c - GCC 和 Clang 之间的执行性能差距
- angular - 访问 ngOnChanges 中的最新输入属性
- php - 在生产环境中为管理员使用 Laravel Debugbar
- laravel - Laravel 从列或外键过滤