You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Python解析Desktop文件?含示例及已尝试方案说明

Python解析Desktop文件求助

示例Desktop文件

[Desktop Entry]
Version=1.0
Type=Application
Exec=/usr/lib/firefox/firefox %u
Terminal=false
X-MultipleArgs=false
Icon=firefox
StartupWMClass=firefox
DBusActivatable=false
Categories=GNOME;GTK;Network;WebBrowser;
StartupNotify=true
Actions=new-window;new-private-window;open-profile-manager;
Name=Firefox
Comment=Browse the World Wide Web
GenericName=Web Browser
Keywords=Internet;WWW;Browser;Web;Explorer;

[Desktop Action new-window]
Exec=/usr/lib/firefox/firefox --new-window %u
Name=New Window

期望实现效果

希望能写出类似以下的Python代码,实现解析Desktop文件并提取名称、动作列表等信息:

desktop_file = parse.parse("firefox.desktop")
print(desktop_file["name"])
for i in desktop_file["actions"]:
    print(i)

已尝试的库

我已经试过desktop-parser库。

内容的提问来源于stack exchange,提问作者AlwaysNur

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 01:49:52