我正在尝试访问存储在 Linux 中安装的磁盘中的数据集。该磁盘的名称是“新卷”。 Python 给我一个错误,
[Errno 2]没有这样的文件或目录
我尝试将数据集保存在 tmp 文件夹中,并且成功加载了数据。如果数据位于“新卷”中,我无法访问它,但我可以通过命令行成功导航到特定文件夹。
这是我的代码:
train_horse_dir = os.path.join("/media/visheshchanana/New\ Volume/horse-or-human/horses")
甚至尝试过这个:
train_horse_dir = os.path.join("//media//visheshchanana//New\ Volume//horse-or-human//horses")
以下作品:
train_horse_dir = os.path.join("/tmp/horse-or-human/horses")
最佳答案
请检查 python 文档 os.path.join(path, *paths) ,它有 2 个参数,中间有一个“,”,因此您可以连接两个路径。
对于您的情况,不需要使用该功能。
路径中存在空格的问题,请不要添加任何“\”或“/”,只需在“完整路径”中使用空格即可,例如(此处为“DVD 播放器”,内部有空格):
#!/usr/bin/env python3
import os
youDatasetPATH = "/Volumes/MacOSx/Applications/DVD Player.app/Contents/MacOS"
print(os.listdir(youDatasetPATH))
关于python - 无法访问名称中含有空格的磁盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56614188/