python - 使用 shutil.move 时出现 Python 3.8 权限错误
问题描述
我正在尝试编写一个 python 代码,它将监视特定文件夹中的任何“修改”事件,然后将行从源 csv 文件复制到目标 csv 文件。我在 Windows 上使用 Python 3.8
复制行后,我想将源文件移动到存档文件夹,这就是我收到“Win32 权限错误”的时候
有人能帮忙吗?
类处理程序(文件系统事件处理程序):
@staticmethod
def on_any_event(event):
if event.is_directory:
return None
elif event.event_type == 'modified':
# Take any action here when a file is place in the Watch Folder.
nsrc_file = event.src_path
dst_file = "C:\\Users\\paramm\\Documents\\Python\\WB_output\\OE_2019.csv"
archive_folder = "C:\\Users\\paramm\\Documents\\Python\\WB_archive"
with open(nsrc_file, "r") as f_input, open(dst_file, "a", newline='') as f_output:
csv_input = csv.reader(f_input)
for row in csv_input:
csv.writer(f_output).writerows(csv_input)
shutil.move(nsrc_file, archive_folder)
错误:PermissionError:[WinError 32] 该进程无法访问该文件,因为它正被另一个进程使用:
解决方案
推荐阅读
- python - 如何将特定字符的字符打印到具有多个字符实例的特定字符?
- node.js - 使用 Terraform 创建 ECS Fargate 任务时运行状况检查失败
- android - 用活动替换android中的部分屏幕
- gradle - gradlew connectedCheck 不生成覆盖率报告
- ms-access - 如何制作每个表单包含多个数据条目的 Access 表单
- drools - 我应该使用自定义方法还是自定义累积功能
- python - Python selenium 获取链接/点击链接
- gitlab - cypress 录制视频在 gitlab-ci 中不起作用
- ssh - Spyder -- 通过代理连接到远程内核
- ios - 如何刷新 WatchApp 并发症