最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Python, PyKeePass - cant append new tag to entry - Stack Overflow

matteradmin14PV0评论

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]
Post a comment

comment list (0)

  1. No comments so far