Help with Python script

SteveH42's Avatar


11 Oct, 2018 07:57 PM

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?

The script is:

import string

from com.infinitekind.moneydance.model import *
root = moneydance.getCurrentAccountBook()

testString = 'lower case'
print testString, ' upshifted becomes ', string.upper(testString)
accts = []
for acct in AccountUtil.getAccountIterator(root):
    sacct_type = acct.getAccountType()
    print '### Processing account ', acct.getFullAccountName(), ' type ', sacct_type, ' number ', acct.getAccountNum()
    if string.upper(sacct_type)=='EXPENSE':
       print '### Expense account'
print '########## END ################'

and when it runs it gives the following error:

lower case upshifted becomes LOWER CASE
### Processing account My Finances type ROOT number 0
Error running script: Traceback (most recent call last):
  File "d:\Users\Steve\Documents\Moneydance\Development Area\Python Scripts\", line 12, in <module>
    if string.upper(sacct_type)=='EXPENSE':
  File "C:\Program Files\Moneydance\jars\mdpython.jar\Lib\string$py.class", line 235, in upper
AttributeError: 'com.infinitekind.moneydance.model.Account$AccountT' object has no attribute 'upper'

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.

  1. 1 Posted by hleofxquotes on 11 Oct, 2018 09:15 PM

    hleofxquotes's Avatar


    For this discussion purpose, string.upper(xxx) will only work if xxx is a string type. In the second case, sacct_type (the argument) is not a string type. Likely, Account.AccountType

    I think what you want to do is replace
    if string.upper(sacct_type)=='EXPENSE':


        if sacct_type == Account.AccounType.EXPENSE:

    I have not actually test above code.

  2. 2 Posted by SteveH42 on 11 Oct, 2018 09:43 PM

    SteveH42's Avatar

    Hi @hleofxquotes

    Many thanks, just a slight typo in your example but

    if sacct_type == Account.AccountType.EXPENSE:

    works a treat!

    Thanks again.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac