调用字程序sub_process= multiprocessing.process(target=copy_file,args=(file_name,source_dir,dest_dir))然后报错TypeError: 'module' object is not callable。 我得pip list有这个模块,为啥显示调用不了
process 的P要大写,sub_process= multiprocessing.Process(target=copy_file,args=(file_name,source_dir,dest_dir));路径传入错误,改source_dir,dest_dir为source_path,dest_path;写入文件的地方没有传入写入内容。改成如下就能运行。
from multiprocessing import Process
import os
def copy_file(source_dir,dest_dir):
file_list = os.listdir(source_dir)
for file_name in file_list:
source_path=source_dir+'/'+file_name
dest_path=dest_dir+'/'+file_name
with open(source_path,'rb') as source_file:
with open(dest_path,'wb') as dest_file:
while True:
data=source_file.read(1024)
if data:
dest_file.write(source_file.read())
else: break
if __name__ == '__main__':
source_dir = 'F:/2021/answerQ/data/trainer'
dest_dir = 'F:/2021/answerQ/data/2017'
sub_process = Process(target=copy_file, args=(source_dir, dest_dir))
sub_process.start()
sub_process.join()
因为代码正在调用模块对象。模块对象是导入模块时得到的类型。在模块对象中调用恰好与包含它的模块同名的类对象。
您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!
速戳参与调研>>>https://t.csdnimg.cn/Kf0y