1 from jinja2 import Environment, FileSystemLoader 2 import json 3 4 5 def generate_html(data): 6 env = Environment(loader=FileSystemLoader(‘./‘)) # 加载模板 7 template = env.get_template(‘模板.html‘) 8 # template.stream(body).dump(‘result.html‘, ‘utf-8‘) 9 10 with open("result.html", ‘w‘) as fout: 11 12 html_content = template.render(data={}) 13 fout.write(html_content) # 写入模板 生成html 14 15 if __name__ == "__main__": 16 result = {} 17 generate_html(result)
#### 脚本执行 添加进度信息 ff = open(‘1.txt‘,‘w‘) def open_file(file_name): try: with open(file_name,‘a+‘)as f: # 例如打开一个大文件 fsize = os.path.getsize(file_name) # 先计算大文件大小 line_list_size = 0 for line_list in f: line_list_size += sys.getsizeof(line_list) # 计算处理文件大小 done = int(float(line_list_size)/ fsize*10) # 计算进度 sys.stdout.write("\r[%s%s] %d%%" % (‘█‘ * done*2, ‘ ‘ * (20 - done*2), 10 * done)) sys.stdout.flush() # 刷新到控制台 except Exception, e: print e return ‘文件操作失败‘ if __name__ == "__main__": file_name = ‘235‘ print ‘---- start ----‘ open_file(file_name) print ‘\n---- end ----‘
原文地址:https://www.cnblogs.com/nanyu/p/11644985.html
时间: 2024-10-09 21:31:43