繁体   English   中英

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

[英]How to know a file exists in the Desktop using Python on Mac OS?

我想查看文件是否在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'

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM