AttributeError: ‘PosixPath‘ has no attribute ‘link_to‘

问题描述

self.root.link_to(self.download_file_path)

报错:

AttributeError: 'PosixPath' object has no attribute 'link_to'

问题解决

PosixPath模块中找不到link_to方法,从逻辑上可以推测这个函数的功能是实现链接功能。这可以用python的os.link() 实现,将self.download_file_path的内容复制到self.root。

参考Python os.link() 方法
os.link(src, dst):
参数
src – 用于创建硬连接的源地址
dst – 用于创建硬连接的目标地址

改成:

import os
...
# self.root.link_to(self.download_file_path)
os.link(self.download_file_path,self.root)

猜你喜欢

转载自blog.csdn.net/qq_36937684/article/details/109654153