【问题标题】:Im am getting FileNotFoundError when trying to create a for in loop尝试创建 for in 循环时出现 FileNotFoundError
【发布时间】:2023-03-13 08:55:01
【问题描述】:

我正在制作image classifier。我已经成功创建了文件夹,我手动将.txt files 放置在每个文件夹中,其中包含来自google 的linksimages

我现在正尝试将每个.txt fileeither 中的图像download 放入每个文件夹类别中的文件夹or 放入每个类别文件夹中.txt 文件,但是我不断收到错误消息。请帮忙。

manually.txt files 放在每个文件夹中,因为它们在父文件夹名称中为PLANTS,但这并没有什么不同。

我希望从带有谷歌图片链接的 .txt 文件中下载所有图片到它们各自的文件夹中,但无论 .txt 是在 PLANTS 主文件夹内还是在 PLANTS 内的每个类别文件夹内,它都不起作用文件夹

相反,我得到以下错误

文件未找到错误

请看附件截图

&

【问题讨论】:

    标签: python-3.x jupyter-notebook google-colaboratory fast-ai


    【解决方案1】:

    Windows NT 中的 NTFS 支持长文件名或带空格的路径。但是,当在命令提示符操作中指定这些文件名或目录名时,它们需要用引号引起来。不使用引号会导致错误消息。

     for i in range(len(folders)):
            path = "content/gdrive/My Drive/Colab Notebooks/Flowers/PLANTS"
            #for creating directory we need path class object so below this: 
            dest_for_creating_directory = path/folders[i]
            #for searchi directory which have spaces we need doubleQuotations that  
            #why user below one in download image function instead of dest. 
            dest_for_searching_directory = path+"/"+folders[i]
    

    注意:最好不要写文件夹/文件名spacemore info

    【讨论】:

    • 你的代码是用python写的吗?代码在python中
    • 这是 python 是的。我没有声明变量名..我只是分配了值。对于附加字符串,我们在 python 中使用连接运算符。
    • 你能按照你希望我写的方式写代码吗? for i in range(len(folders)): path = Path('content/gdrive/My Drive/Colab Notebooks/Flowers/PLANTS') dest = path/folders[i] dest.mkdir(parents=True, exist_ok=True ) 链接 = 路径(files[i]) download_images(links, dest, max_pics=200)
    • @DarrenJay 已更新。检查它是否工作。 dest.mkdir(parents=True, exists_ok=True) 是否正在创建目录?检查也
    • 也检查一下并尝试打印 dest 变量显示您可以看到 dest 的值。
    猜你喜欢
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 2017-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    相关资源
    最近更新 更多