我试图运行这段代码(https://github.com/ryanwhalen/patentsview_data_download/blob/master/patentsview_download.py),并得到以下错误:
Traceback (most recent call last):
File "...\patentsview_data_download-master\221113\patentsview_download_221113.py", line 285, in <module>
download_and_parse_tsv(url)
File "...\patentsview_data_download-master\221113\patentsview_download_221113.py", line 232, in download_and_parse_tsv
write_to_db(tsv_name, tablename)
File "...\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: '...\patentsview_data_download-master\\221113/g_applicant_not_disambiguated.tsv2'有人能让我知道怎样才能纠正错误吗?谢谢。
我期待运行这段代码并下载专利数据集。
发布于 2022-11-13 17:34:50
这是因为在第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 processinghttps://stackoverflow.com/questions/74423192
复制相似问题