Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Mac OS上使用Python知道桌面上存在文件?_Python_Macos - Fatal编程技术网

如何在Mac OS上使用Python知道桌面上存在文件?

如何在Mac OS上使用Python知道桌面上存在文件?,python,macos,Python,Macos,我想查看Mac OS的桌面上是否有文件,并编写代码: if path.exists('~/Desktop/AZDif.png'): print 'Yes' else: print 'No, the file is not there' 我看到文件实际上在桌面上时不在桌面上。如何正确编写代码?以下是我为使用Python的Mac OS找到的解决方案: if path.exists(path.expanduser('~/Desktop/AZDif.png')): print

我想查看Mac OS的桌面上是否有文件,并编写代码:

if path.exists('~/Desktop/AZDif.png'):
    print 'Yes'
else:
    print 'No, the file is not there'

我看到文件实际上在桌面上时不在桌面上。如何正确编写代码?

以下是我为使用Python的Mac OS找到的解决方案:

if path.exists(path.expanduser('~/Desktop/AZDif.png')):
    print 'Yes'

也应该有一种使用绝对路径的方法。我将检查并改进答案

这个链接有用吗?这不是针对Mac OS的,但一般来说是的。你不需要编辑你的问题来包含解决方案,你可以把它写下来作为答案。好的,我把它作为答案。