问题描述
我写了一个小程序代码,它会自动从 kaggle 下载一些东西。整个内容应下载到文件夹 C:/Users/User/Documents/dataset
。这是问题,当我第一次运行代码时,路径是正确的。如果我再次运行代码,我会得到以下路径 C:/Users/User/Documents/dataset/dataset
。问题是每次执行程序时都会添加文件夹dataset
。这是什么原因?
我在 Jupyter Notebook
下使用 Anaconda
import pathlib
import json
import os
dir_path = ""
dataset_name = "stroke-prediction-dataset"
dir_path = pathlib.Path("").resolve()
save_path = dir_path / "dataset"
# Therefore it also never recognizes this If statement
# because it always creates a new folder
if (save_path / pathlib.Path(dataset_name+".zip")).is_file() == False:
USERNAME_kaggle = "..."
TOKEN_kaggle = "..."
if not os.path.exists(save_path):
os.makedirs(save_path)
os.chdir(save_path)
# Download the dataset from kaggle
!pip install kaggle
print()
api_token = {"username":USERNAME_kaggle,"key":TOKEN_kaggle}
with open(os.path.expanduser('~') + '/.kaggle/kaggle.json','w') as file:
json.dump(api_token,file)
!kaggle datasets download -d fedesoriano/stroke-prediction-dataset
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)