Author Topic: How to test for not set iptc field  (Read 1734 times)


  • Newbie
  • *
  • Posts: 2
  • Karma: 0
  • Scribus User
How to test for not set iptc field
« on: January 28, 2015, 03:20:00 pm »
I am using Scribus with Python scripting and exiv2 iptc library. I am using scripting and ITPC fields in photo's to place them in position.
Some of my photos have a iptc field Application2.Subject and others do not. I want all to have it and can script to create the field if it does not exist by simply writing say "0" to the non existant field and it will be created.

My problem is that it will overwrite those that already exist. I need to test if the field exists so that I can copy the data first and then rewrite it back to the field.

I am using exiv2 to obtain the data but when I try to copy any existing data to a variable I get an error that the key is not set, for those photo's without the field. I would have hoped to use say...
if metadata['Iptc.Application2.Subject'].value[0] == None
   then write the "0" creating the field
For those that have it I could write back the saved variable

Can anybody help please to test for missing field without an error, I am not an expert.