【问题标题】:patent download, PermissionError: [WinError 32] The process cannot access the file because it is being used by another process专利下载,PermissionError: [WinError 32] 进程无法访问该文件,因为它正被另一个进程使用
【发布时间】:2022-11-14 01:55:09
【问题描述】:

我正在尝试运行这段代码(https://github.com/ryanwhalen/patentsview_data_download/blob/master/patentsview_download.py),并收到以下错误:

Traceback (most recent call last):
  File "D:\0C\Downloads\Whalen_Ryan\patentsview_data_download-master\221113\patentsview_download_221113.py", line 285, in <module>
    download_and_parse_tsv(url)                                          
  File "D:\0C\Downloads\Whalen_Ryan\patentsview_data_download-master\221113\patentsview_download_221113.py", line 232, in download_and_parse_tsv
    write_to_db(tsv_name, tablename)                                  
  File "D:\0C\Downloads\Whalen_Ryan\patentsview_data_download-master\221113\patentsview_download_221113.py", line 195, in write_to_db
    os.remove(os.getcwd()+'/'+cleaned_file)                       
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'D:\\0C\\Downloads\\Whalen_Ryan\\patentsview_data_download-master\\221113/g_applicant_not_disambiguated.tsv2'

有人可以让我知道如何修复错误吗?谢谢。

我期待运行这段代码并下载专利数据集。

【问题讨论】:

    标签: python permissionerror


    【解决方案1】:

    这是因为在第 142 行,中间文件被打开但从未关闭。这是一行:

    infile = open(os.getcwd()+'/'+cleaned_file, 'r', encoding = 'utf-8')
    

    我建议像这样重写它:

    with open(os.getcwd()+'/'+cleaned_file, 'r', encoding = 'utf-8') as infile:
        # here goes the rest of file processing
    

    【讨论】:

      猜你喜欢
      • 2015-11-13
      • 2015-01-28
      • 2017-06-02
      • 2021-09-21
      • 2019-11-26
      • 1970-01-01
      • 2020-10-31
      • 2018-10-28
      • 2021-09-28
      相关资源
      最近更新 更多