Import Parameters from files in a subfolder

Viewed 26

There must be a better solution than the abomination i have cooked up.

I have a variety of devices that run on slightly different hardware. I communicate with said devices and test their functionality which is influenced by their hardware. So I have a subfolder with a file for each device with different parameters.

Mainfolder
|--> Subfolder ( with 20 Devices files.py )

For example different upper and lower boundries for acceptable voltage levels. But every Devices runs the same test function but overrides the boundries with the subfolder file.
My current approach is that at the start of the test the device is selected and the device file is added via:

sys.path.append(str(os.getcwd()) + "\Devices")
if(Device==xyz):
     from Device_xyz import *

I have two main issues here:

  1. The import is dirty since its in a subfolder. It works but Vs Code gives me warning that the file does not exist, until he actually tries to load it. Probably because of the weird os.path adding.

  2. VS Code is strongly confused by this. It works but every parameter from the imported file is underlined as not found until the code executes.

Any kinda soul with some input how to do this more professional would be much appreciated!

1 Answers
Related