如何在Mac OS上使用Python知道桌面上存在文件?
我想查看Mac OS的桌面上是否有文件,并编写代码:如何在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
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的,但一般来说是的。你不需要编辑你的问题来包含解决方案,你可以把它写下来作为答案。好的,我把它作为答案。