james-see / iptcinfo3

iptcinfo working for python 3 finally do pip3 install iptcinfo3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can write to some of the IPTC but not to keywords

pablo-01 opened this issue · comments

commented

Hi,

I just started using iptcinfo3 and have a quick question. Is there an example of how to append keywords?

I followed the usage example and I can write some to IPTC like headline but when I try to add a keyword it throws an error and I was wondering if anyone could help.

`from iptcinfo3 import IPTCInfo

info = IPTCInfo('man.jpg')
print(info['keywords'])

info['keywords'] = 'someKeyword'
info.save()`
`[b'glasgow', b'scotland', b'black hat']
Traceback (most recent call last):
  File "F:\clarifai\iptc.py", line 9, in <module>
    info['keywords'] = 'someKeyword'
  File "C:\Users\pc\AppData\Local\Programs\Python\Python36\lib\site-packages\iptcinfo3.py", line 706, in __setitem__
    self._data[key] = value
  File "C:\Users\pc\AppData\Local\Programs\Python\Python36\lib\site-packages\iptcinfo3.py", line 565, in __setitem__
    raise ValueError("%s must be iterable" % name)
ValueError: keywords must be iterable
[Finished in 0.2s]`

It prints keywords ok just can not write them back.

commented

Found the problem, stupid mistake of not making it an array (note to self: read error messages).

I do have one question, how to append keywords rather than replacing them?

thanks

commented

@PavKmiec glad you figured it out. I believe you just append like a normal list type. So, info['keywords'].append('someKeyword')

commented

@PavKmiec let me know if that works.

commented

that worked, thanks @jamesacampbell

commented

@PavKmiec if Clarifai finds my package useful, please consider sponsoring it. I have added a sponsor link to the repo using my Patreon account. Thanks for using it!