Python脚本找不到路径

2024-10-01 02:29:28 发布

您现在位置:Python中文网/ 问答频道 /正文

当我在脚本中执行以下行时:

if os.path.exists('/home/jsc0606/Desktop/project/myfile.py')

我得到False。但是,当我在终端的同一个目录中执行同一行时,我得到True。有人知道为什么Python在执行脚本中的那一行时找不到文件吗?在


Tags: pathpy目录project脚本false终端home
1条回答
网友
1楼 · 发布于 2024-10-01 02:29:28

the docs关于os.path.exists所述:

On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists.

我认为可能是这样的:您可能是以不同的权限运行脚本。在

相关问题 更多 >