⽅法⼀
def _read(from_filename, from_encode):吉尔吉斯族
with open(from_filename, "r", encoding=from_encode) as f:
for lines in iter(lambda: tuple(islice(f, 1000000)), ()):
_queue.put(lines)
电子产品世界
_queue.put(None)
def convert_file_to_utf8(p_task, **kwargs):
"""码流分析仪
转化ftp下载的⽂件格式
长会口大桥:param p_task: 不同下载⽂件的task_id
:
param kwargs:
中世纪欧洲地图:return:
"""
local_file = kwargs['ti'].xcom_pull(task_ids=p_task)
convert_file = local_file[0:len(local_file) - 3] + "csv"
th = Process(target=_read, args=(local_file, "GB18030"))林木
林地权属争议处理办法
th.start()
with open(convert_file, "w", encoding="utf-8") as f:
while True:
lines = _()
if lines is None:
break
f.write(''.join(lines))
th.join()
⽅法⼆
with open(filename, 'r', encoding="GB18030") as f:
i = 0
for row_ in f:
row = row_.strip().encode("utf-8").decode("utf-8")
i += 1
性能⽐较:对1M⼤⼩⽂件进⾏实验。⽅法⼀的消耗时间为44893微秒,⽅法⼆消耗时间为49015微秒。使⽤⽅法⼀⽐使⽤⽅法⼆转换⽂件格式更快。