0
votes

I have the following directory structure

Root/
    Main.py
    /Controller->
        /MotorController->
            MotorController.py
            __init__.py
    /Tools->
        test.py

Now Tools/test.py have some test code that basically imports MotorController.py using relative path like the following

Tools/test.py from ..Controller.MotorController.MotorController import *

This gives an error that relative path cannot be used on non-package. Moving the test.py to the Root directory solves the problem but I really want my scripts to be in the Tools directory. How do I do this ?.

This is a related question; Say I make a package MotorController.MotorController.py like above that works on a particular robot. Now I want to have some calibration script that only works on that particular robot and hence I was planning to put that script in the same directory as MotorController.py. But it seems like one can't run a script from the same directory as the Package due to relative path and etc. Is there a way around or what is the general principle in such cases.

2

2 Answers

0
votes

To make a package of a folder you must include and __init__.py file (can be empty).
So you should add one of these files in each folder of your Root structure.

0
votes

You need a file to indicate that the folder is a python package.

the standard is a (often empty) __init__.py file, note that there are 4 underscores total.