import custom "module" - file location?

Greetings. Apologies in advance, I have some C programming background but I am a complete newbie to python. I am trying to do something simple - I’m trying to organize my project in to separate files much like I usually do with my C based projects. But for whatever reason, I cannot get the “import” functionality to work for a file I’ve created. I suspect that it has something to do with my file location or something simple I am missing in a file header, etc. I have a basic file named test.py with a simple function in it (note that the excerpt below is literally all I have in the file).

def testFunction:
    print("test")

In the same directory, I have another simple file named test_main:

import sensor, image, time, test

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    print(clock.fps())

When I try to run test_main, I get an ImportError: No module named ‘test’.

Both files are in the same directory. Originally they were not in the OpenMV folder in “mydocuments”, but I tried relocating them there with no success. So what am I missing? Has to be something simple/stupid. My understanding is that per ~feb of this year, the openmv ide supported importing like this - am I mistaken?

Rapid feedback appreciated - thanks!

-Chris

The OpenMV Cam compiles the code so the test.py file had to be on its flash drive. OpenMV IDE doesn’t actually do anything other than act as an editor and debug window.

That said, the IDE is quite smart and if you have that test.py file in the OpenMV folder in my documents OpenMV IDE will find it and ask if you’d like to copy it to the camera.

Thanks. If I make a change to test.py, I do get prompted with the following - Module test on your OpenMV Cam is different than the copy on your computer. Would you like OpenMV IDE to update the module on your Open MV Cam?
If I click yes, I then get the same error - ImportError: no module named ‘test’.
So its odd, OpenMV can find the test.py file, but there is still some sort of import error. Any ideas?

Can you confirm the test.py module was copied over to your OpenMV Cam’s disk? Note that windows caches writes so it make take a second for the file to actually make it to the device.

Just to confirm, “disk” is referring to the folder that pops up upon physical USB connection, correct? If so, then no, I do not see test.py carried over to this folder. In fact, if I use the “save open script to openMV cam” command, I don’t see test_main.py saved to this folder either. So apparently the problem is deeper than I thought. What would be preventing file transfer to the OpenMV cam? Certainly I can run new scripts through the IDE without issue.

Thanks for the help!

-Chris

Hmm, I think the IDE then has bound itself to the wrong disk. In the next firmware release we bind the IDE to a particular disk name.

So, check the drive in OpenMV IDE (on the status bar) that OpenMV IDE thinks is the disk. It mostly guessed wrong.

In the next release we’ve made this better.

Thanks, I moved to my backup OpenMV cam which didn’t have the same issue, I’ll check the drive the next time I use the other cam.