Iterating through accounts in Python

kwhitney09's Avatar

kwhitney09

08 Dec, 2011 04:48 PM

I was using:

for i in range(0, root.getHighestAccountNum()):
    myAccount = root.getAccountById(i)

to iterate through Moneydance accounts.

However, this:

for i in range(0, root.getHighestAccountNum()+1):
    myAccount = root.getAccountById(i)

gets the full account list. Why the +1? Am I misunderstanding the range of account id numbers?

Thanks

  1. 1 Posted by Jessica Little on 08 Dec, 2011 06:30 PM

    Jessica Little's Avatar

    When you use the range function in Python, the number produced are inclusive of the beginning of the range but exclusive of the end. So, for example, this code:

    for i in range(0,3):
      print i,
    

    would print "0,1,2", not "0,1,2,3". Since you want to print all of the accounts, including the last one, you have to add 1 to the second argument of the range command to get the desired results.

    Hope that clears things up. Please let me know if I can be of further assistance, and thanks for your interest in Moneydance!

    Jessica Little
    Moneydance Support

  2. 2 Posted by kwhitney09 on 08 Dec, 2011 06:40 PM

    kwhitney09's Avatar

    My python novice status is showing!

    Thanks for the super-quick response.

  3. Jessica Little closed this discussion on 08 Dec, 2011 07:37 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? 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