如何使用PyGTK将列表作为文件属性写入

2024-05-29 02:13:31 发布

您现在位置:Python中文网/ 问答频道 /正文

enter image description here

Linux Mint创始人的comment指出,Nemo较新版本中的文件标志可以通过编程方式访问,如下面使用Python和PyGTK的示例所示:

import gio
file = gio.File("/home/guest/Documents/Todo")
emblems = file.query_info("metadata::emblems")
print emblems.get_attribute_as_string("metadata::emblems")

以这种格式输出一些东西

[emblem-important, emblem-urgent]

如您所见,存储为metadata::emblems的对象是一个列表(我猜是字符串)。但是,在Gio.FileInfo上的PyGTK documentation中,我找不到访问(读或写)数组类型属性的方法。你知道吗

有什么方法可以做到这一点(即阅读单个标志或按程序设置新标志)?如果是,我怎样才能做到这一点?你知道吗


Tags: 文件方法版本标志linuxcommentfilepygtk
1条回答
网友
1楼 · 发布于 2024-05-29 02:13:31

奇怪的是,没有方便的方法来实现这一点,但是您可以直接调用File.set_attribute,使用STRINGV作为类型。你知道吗

f.set_attribute('metadata::emblems', gio.FILE_ATTRIBUTE_TYPE_STRINGV, ['emblem-important', 'emblem-urgent'])

相关问题 更多 >

    热门问题