How to import a Custom Class?

I would like to do some OOP. I have the code working if I just declare the class in the file but for obvious reasons that is getting a bit over crowded. Ive created a new file in the same mode directory. In the script, I try both

import "newClass" and from "newClass" import *

In both cases I’m getting the ImportError: No module named newClass

I’m guessing it could be a permission issue or I’m just dumb and don’t know what I’m doing. Both are equally likely.

Here is the output from console

error reloading: Traceback (most recent call last):
  File "/home/music/EYESY_OS/engines/python/", line 258, in reload_mode
    imp.load_source(self.mode, self.mode_root+'/')
  File "/sdcard/Modes/Python/ZHS - Boids//", line 6, in 
    from Boids import *
ImportError: No module named Boids

@chrisk anything you could say on this :grimacing:

Here is one way to do it. Say you have the file in the folder with

class TestClass:
    def hi(self):
        print 'hi'

Then in you can do this:

import imp

def setup(screen, etc) :
    test = imp.load_source('test', etc.mode_root +  '')
    obj = test.TestClass()

def draw(screen, etc) :

You can import a specific class or the whole package. You place import statements at the top of your source files..

Thanks ill give that a try and report back

yea that’s what I was doing so not sure why its not working. I wonder if its related to another issue im having. Certain things arent working as expected. I developed the mode in VScode and items like using the pygame.math.vector2 class are not accessible once I move over to the eyesy even though I have the import pygame.math at the top of the script.

Also basic sys commands like type() are not running on the eyesy but do in the emulator on VS code.

The following code produces the subsequent print statement in the Eyesy console for example:

        print("----------result type: " + str(type(vectorToLimit)))


whereas in the VScode environment it outputs as expected


Let me know if you have any insights as to the related issue i shared below.