I can’t understand this…
Cannot get this code to run and I’ve no idea why it is a syntax error.
try:
newT.read()
#existingArtist = newT['Exif.Image.Artist'].value
#existingKeywords = newT['Xmp.dc.subject'].value
except KeyError:
print "KeyError"
else:
#Program will NOT remove existing values
newT.read()
if existingArtist != "" :
newT['Exif.Image.Artist'] = artistString
print existingKeywords
keywords = os.path.normpath(relativePath).split(os.sep)
print keywords
newT['Xmp.dc.subject'] = existingKeywords + keywords
newT.write()
except:
print "Cannot write tags to ",filePath
Syntax error occurs on the last “except:”. Again…I have no idea why python is throwing a syntax error (spent ~3hrs on this problem).
You can’t have another
exceptafter theelse. Thetry,except, andelseblocks aren’t like function calls or other code – you can’t just mix and match them as you like. It’s always a specific sequence:If you want to catch an error that occurs during the
elseblock, you’ll need anothertrystatement. Like so:FYI, the same applies if you want to catch an error that occurs during the
exceptblock – in that case as well, you would need anothertrystatement, like this: