"NameError: name 'moneydance' is not defined" after import

md_oz's Avatar


17 Apr, 2019 09:47 PM

I have a modified version of the set_prices.py script (https://infinitekind.com/dev/set_prices.py), as shown below.

book = moneydance.getCurrentAccountBook()
currencies = book.getCurrencies()
def setPriceForSecurity(symbol, price, dateint):
  price = 1/price
  security = currencies.getCurrencyByTickerSymbol(symbol)
  if not security:
    print "No security with symbol/name: %s"%(symbol)
  if dateint:
    security.setSnapshotInt(dateint, price).syncItem()
  print "Successfully set price for %s"%(security)

def main(): setPriceForSecurity('AAPL', 219.9175, 0) return

if name == 'main': main()
When I 'Open Script' and 'Run' in the MoneyBot interface it successfully executes and "Successfully set price for Apple Inc." message is displayed on the console.

I have another program, set_prices_via_import.py, which imports the set_prices.py script and then executes it. I've simplified/sanitized the script below:

import sys
from os.path import expanduser

import_path = expanduser("~") + r"\Desktop\Now\Code\Python\Unit\MoneyBot\wip" # set_price.py location sys.path.insert(0, import_path) # add set_price.py location to the python path

print(type(moneydance), moneydance) # check that moneydance is available

import set_prices # import set_prices.main() # execute
When I run this script via MoneyBot it fails to execute yielding a "NameError: name 'moneydance' is not defined" error.

By investigating moneydance in the successful script I see that moneydance == com.moneydance.apps.md.controller.Main@147efb4d.

I've tried passing a global variable, importing the controller, but I haven't found the right approach/syntax.

Any suggestions on how do I remedy this?

Thank you.

  1. System closed this discussion on 17 Jul, 2019 09:50 PM.

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

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