Help with Python script

Hi
I have used a number of third party Python scripts in the past but since upgrading to MD2017 most of these no longer work due to changes in the Moneydance api (already described in this forum). I have therefore tried to upgrade some of these to the new api but my Python knowledge is a bit basic!
In order to try and understand what is happening, I have written a very simple short script and it fails and I don't understand why - perhaps someone could enlighten me?

As you can see, the first use of string.upper worked but the second one failed - why??

My ultimate aim is to select only EXPENSE account types but I could get the condition test to work - hence this short test script.
These seems to be very little in the way of examples or documentation for the new api in python.