【问题标题】:Python Directory Display in Finder, Explorer, Dolphin, etc... (Cross-Platform)Finder、Explorer、Dolphin 等中的 Python 目录显示...(跨平台)
【发布时间】:2010-09-01 15:54:40
【问题描述】:

我想找到一种在默认文件系统查看器(Windows Explorer、Finder、Dolphin 等)中查看目录的方法,该方法适用于所有主要平台。 为了写这篇文章,我没有 Linux 和 OSX 的详细知识。是否有一些脚本可以满足我的需求?

【问题讨论】:

    标签: python cross-platform directory


    【解决方案1】:

    OSX:

    os.system('open "%s"' % foldername)
    

    窗户:

    os.startfile(foldername)
    

    Unix:

    os.system('xdg-open "%s"' % foldername)
    

    综合:

    import os
    
    systems = {
        'nt': os.startfile,
        'posix': lambda foldername: os.system('xdg-open "%s"' % foldername)
        'os2': lambda foldername: os.system('open "%s"' % foldername)
         }
    
    systems.get(os.name, os.startfile)(foldername)
    

    【讨论】:

    • Unix 是否与 Linux 兼容(愚蠢的问题,我知道),它是否与所有发行版兼容?
    • Linux 是一个类 Unix 系统。是的,如果默认安装了 xdg-open(所有现代发行版),它与所有发行版兼容。 xdg-open 是打开文件夹最兼容的方式,因为没有通用方式来执行此操作,因为您需要为每个桌面管理器使用不同的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-25
    • 2011-11-08
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多