Devs: Multi-File Python Projects

@richard , @jwunderl , & other devs: I’m seeking assistance. :smiley: Second of two threads.

In another thread[1], I was attempting to assist one of our forum members with Python and the project explorer. We can create multi-file projects in JavaScript just fine. Namespaces are possible but not required.

I’m curious on where we are with similar projects in Python.

I can see that some translation helpers have been added to attempt to support namespaces in Python. The following JavaScript code gets translated to the Python code below it by the editor.

// JavaScript version
namespace game1 {
    export function start() {
        // Do stuff
    }
}
# Python version
@namespace
class game1:
    def start():
        # Do stuff
        pass

I cannot quite get the Python namespace bit working, though I suspect it’s a work in progress. No worries. If I simply add Python code to a second file (named, say, game1.py), though, the editor behaves differently from how it behaves with JavaScript.

In JavaScript, you can split code across multiple files and it works just fine. No alterations needed. Functions can be referenced across files without any additional decoration. Code that does not reside within functions runs as if it existed within an on start container in Blocks … even if that code is spread across multiple files.

In Python, it seems like, even without the @namespace and class decorations, the editor still creates an “implicit” namespace around code that resides outside of the main.py file. This is IntelliSense kicking in when I try to call the Game1_Start() function found in the game1.py file in my project.

image

Are namespaces required in multi-file Python projects? If so, are they ready to use, or are they a work in progress?


[1] MakeCode Arcade Explorer Help

2 Likes

Some code, if you’d like. :laughing: Can’t believe I forgot to include it!

1 Like

this would not surprise me… tbh, we don’t test the multi-file python scenario (I didn’t even know it worked at all) so it may be broken in unexpected ways.

2 Likes

I think this would be cool to have a way to use many files in python, like a file of a certain instance and another (entire segments, of course) and have it call a file at the end which links the code with an extra-efficient couple of instructions.