Closed FlaminMad closed 6 years ago
To import something from another directory you can do
from FOLDER.FILE import CLASS
However, you need to add a blank file in the directory called init.py as this will be used by python when you run your program.
You should have all of the files in separate 'packages' in your src folder, any shared files can go in which ever package you think they best fit, and other packages can just import them from their.
You want to avoid having a 'shared resources folder' because it will end up being a dumping ground for everything that doesn't fit nicely into a single package, you're better just picking one of the suitable packages and placing it there, and having everything else use it from their.
I cant seem to get the above working no matter what I do, so have had to result to using:
import sys sys.path.insert(0, '../dataLoggingTool') #Allow finding modbus file from Modbus import comClient #Import Modbus Comms Class ...Other files
Not the best option I'm assuming however if you can correct my ways ill try again!
@pet1330 - Based on the fact I'm now just importing everything using the above method, im going to close this issue as 'resolved via an alternate method'. Re open it if you disagree :+1:
I would probably leave this open as this isn't the correct way of doing it, but I'll look into a bit further then I get a chance
Any news on said problem? :+1: I wont be restructuring this repository specifically, but plan to rewrite some of the code and create a public repository for it soooon so wanna make sure i get it right! lol
Sorry, I've not had a chance to look into it. I'll take a look when I get back from BJC. I wouldn't create a new repository for it. Just make this one public. (via the settings tab)
Stop checking your emails at BJC!!!! :smile: Supposed to be a holiday not a worktrip!!!! :palm_tree:
Im only splitting it as I don't want to include all of the programs, only a certain one :smile: No rush!
I guess I can close it as it's not needed anymore, reopen it if you still want me to take a look at it though :smiley:
So currently there are a variety of classes I use across all of my src projects. A classic example of this is Modbus.py Is there a place in which i can but these so they are common to all projects (As in with the fancy new structure can i have a 'shared resources folder' or something like that)
Also, how do i then import them if they're not in the run directory?