admin管理员组文章数量:1433160
I cant find out way how to append new tag in entry via PyKeePass first of all lets show my code i was expecting should work:
# env='ACC'
def appendTagKP(env):
kp = PyKeePass(r'D:\users\\NewDatabase.kdbx', password=decodeStr(kp_password))
test = kp.find_entries(tags='test', first=False)
if test:
for i in test:
print(i.title)
i.tags.append(env)
print(f'After tags edit: {i.tags}')
print(i.password)
kp.save()
Type of "i.tags" is 'LIST' thats why i expecting that append should work...
In kdbx i have two entries that already have one tag "test":
Title: jhr
tags: ['test']
and
Title: jhrjhr
tags: ['test']
When i run this code, output is just those prints without new tags, i've alreday tried some small edits thats to AI and google but nothing helped. This is my last chance :D
My expect is output where my entries have two tags: After tags edit: ['test','ACC']
I cant find out way how to append new tag in entry via PyKeePass first of all lets show my code i was expecting should work:
# env='ACC'
def appendTagKP(env):
kp = PyKeePass(r'D:\users\\NewDatabase.kdbx', password=decodeStr(kp_password))
test = kp.find_entries(tags='test', first=False)
if test:
for i in test:
print(i.title)
i.tags.append(env)
print(f'After tags edit: {i.tags}')
print(i.password)
kp.save()
Type of "i.tags" is 'LIST' thats why i expecting that append should work...
In kdbx i have two entries that already have one tag "test":
Title: jhr
tags: ['test']
and
Title: jhrjhr
tags: ['test']
When i run this code, output is just those prints without new tags, i've alreday tried some small edits thats to AI and google but nothing helped. This is my last chance :D
My expect is output where my entries have two tags: After tags edit: ['test','ACC']
Share Improve this question asked Feb 20 at 11:15 Pepys SPepys S 111 bronze badge1 Answer
Reset to default 0Looking at the code, you see there are @property
, @getter
and @setter
defined for Entry.tags
. Under the hood tags are stored as single sep
delimited string (default sep
is semi-colon). The getter parse the string to list, setter joins list elements to produce string.
This will do (now tested):
tags = i.tags # get the current tags
tags.append(env) # append the new tag value
i.tags = tags # assign again to Entry.tags property
or as one liner
i.tags = i.tags + [env]
本文标签: pythonPyKeePasscant append new tag to entryStack Overflow
版权声明:本文标题:Python, PyKeePass - cant append new tag to entry - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741440504a2378887.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论