提交 87cb0880 编写于 作者: Y yejianwu

use 'with open(...) as f' in python

上级 92686bae
......@@ -74,9 +74,8 @@ def tuning_param_codegen(binary_dirs,
binary_dirs, binary_file_name, variable_name)
if os.path.isfile(output_path):
os.remove(output_path)
w_file = open(output_path, "w")
with open(output_path, "w") as w_file:
w_file.write(cpp_binary_source)
w_file.close()
def parse_args():
......
......@@ -44,14 +44,14 @@ def encrypt_opencl_codegen(cl_kernel_dir, output_path):
for file_name in os.listdir(cl_kernel_dir):
file_path = os.path.join(cl_kernel_dir, file_name)
if file_path[-2:] == ".h":
f = open(file_path, "r")
with open(file_path, "r") as f:
header_code += f.read()
encrypted_code_maps = {}
for file_name in os.listdir(cl_kernel_dir):
file_path = os.path.join(cl_kernel_dir, file_name)
if file_path[-3:] == ".cl":
f = open(file_path, "r")
with open(file_path, "r") as f:
code_str = ""
for line in f.readlines():
if "#include <common.h>" in line:
......@@ -70,9 +70,8 @@ def encrypt_opencl_codegen(cl_kernel_dir, output_path):
if os.path.isfile(output_path):
os.remove(output_path)
w_file = open(output_path, "w")
with open(output_path, "w") as w_file:
w_file.write(cpp_cl_encrypted_kernel)
w_file.close()
print("Generate encrypted opencl source done!")
......
......@@ -86,9 +86,8 @@ def opencl_codegen(output_path,
platform_info_file_name)
if os.path.isfile(output_path):
os.remove(output_path)
w_file = open(output_path, "w")
with open(output_path, "w") as w_file:
w_file.write(cpp_cl_binary_source)
w_file.close()
def parse_args():
......
......@@ -173,9 +173,8 @@ def convert_to_source(net_def, mode_pb_checksum, template_dir, obfuscate,
with open(output_dir + 'tensor_data' + '.cc', "wb") as f:
f.write(source)
if not embed_model_data:
f = open(output_dir + model_tag + '.data', "wb")
with open(output_dir + model_tag + '.data', "wb") as f:
f.write(bytearray(model_data))
f.close()
# generate op source files
template_name = 'operator.jinja2'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册