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 badge
Add a comment  | 

1 Answer 1

Reset to default 0

Looking 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