How to open/read a file within my own Python extension's mxt zip package?

Stuart Beesley (Mr Toolbox)'s Avatar

Stuart Beesley (Mr Toolbox)

24 Feb, 2021 04:54 AM

If I have a self-installed runtime extension - Python based, how can I get another file within my own mxt package.

The script itself streams from the zip (done by Moneydance when the script installs)..

So I want to do the same, e.g. load a help file, or perhaps an icon..

(I don't want to have to open the mxt on disk, and unzip etc. I want to stream in the same fashion)

Many thanks

  1. Support Staff 1 Posted by Sean Reilly on 24 Feb, 2021 02:13 PM

    Sean Reilly's Avatar

    Extensions can call getClass().getResourceAsStream(String resourceName) in order to load a file included in the mxt. That needs to be the only way that you access anything included in the extension as it checks the signature on the resource as it loads.


    Sean Reilly
    Developer, The Infinite Kind

  2. 2 Posted by Stuart Beesley ... on 24 Feb, 2021 02:20 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    Thanks. I’ll play with this. Does it work for Py extensions?

  3. 3 Posted by Stuart Beesley ... on 24 Feb, 2021 02:58 PM

    Stuart Beesley (Mr Toolbox)'s Avatar


    def initialize(self, extension_context, extension_object):
    self.moneydanceContext = extension_context
    self.extensionObject = extension_object
    print "%s" %self.getClass().getResourceAsStream("readme.txt") print "%s" %self.extensionObject.getClass().getResourceAsStream("readme.txt")

    == Both report None.... the file readme.txt is at the root of the mxt


  4. 4 Posted by Stuart Beesley ... on 25 Feb, 2021 05:13 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    Updating this post with latest Info for any interested readers...

    from Sean: 'It needs to call getClass() on an object that is of a class loaded using the classloader of the extension.'.

    Thus, it will not work at the moment...

    He mentioned that he will look to add variable called moneydance_extension_loader which is set to the ClassLoader object for the extension in a future build. With this you can then call the method public InputStream getResourceAsStream​(String name) in order to get an inputstream for anything bundled in the mxt. You'll need to give the full path to the file within the mxt's zip archive.


  5. 5 Posted by Stuart Beesley ... on 20 Mar, 2021 12:37 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    This is fixed in build 3051. The moneydance_extension_loader variable exists and works well. Thanks.

  6. Stuart Beesley (Mr Toolbox) closed this discussion on 20 Mar, 2021 12:37 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