1、往文件里写具有一定格式的数据:
# write obj 3D face methods
with open(obj_name, 'w') as f:
# write vertices & colors
for i in range(vertices.shape[1]):
s = 'v {:.4f} {:.4f} {:.4f} {} {} {}\n'.format(vertices[1, i], vertices[0, i], vertices[2, i], colors[i, 2],
colors[i, 1], colors[i, 0])
f.write(s)
# write f: ver ind/ uv ind
for i in range(triangles.shape[1]):
s = 'f {} {} {}\n'.format(triangles[0, i], triangles[1, i], triangles[2, i])
f.write(s)
2、多线程开启与控制:
import threading
import time
class DloadThread:
def __init__(self):
self.exit = False
def terminate(self, flag):
self.exit = flag
def setparam(self, data):
self.params = data
def run(self, params=None):
self.params = params
while not self.exit:
str = threading.current_thread().getName()
print(str, self.params)
print(str, "停止")
aa = DloadThread()
bb = DloadThread()
thread = threading.Thread(target=aa.run, args=(22,), name="aa")
threadb = threading.Thread(target=bb.run, args=(25,), name="bb")
threadb.start()
thread.start()
data = input("输入改变的参数")
aa.setparam(data)
data = input("是否退出线程")
aa.terminate(True)