Code: Select all
sys.path.append(os.getcwd() + "\Things")Dave.
Code: Select all
sys.path.append(os.getcwd() + "\Things")Are you trying to build something that will look into the Things directory for subprograms to run in any current directory you happen to be running the program in or do you want it to go after your ~/Things directory specifically? I guess I was just wondering if you have a lot (or at least two) Things directories on your system. The usual name for such a directory is ~/bindavef21370 wrote:I have a script that needs access to a folder called Things in my working directory to load some modules. What I'm using is this...... but it seems a bit clumsy using sys and os to do something so simple. What's the best way, bearing in mind it needs to be cross platform.Code: Select all
sys.path.append(os.getcwd() + "\Things")
Code: Select all
import Things.mymodule as mymoduleThat's an option but may complicate things. The code's a text based adventure framework aimed at getting kids coding by "filling in the blanks" at first then pushing them to create & change the properties and functions of objects in the game. Really need to keep it simple, can post more details over this weekend.elParaguayo wrote:Apologies if I'm missing something. Is Things a subfolder of the folder in which your python script is located?
Why not just add an empty __init__.py file inside Things and then, in your code do:[/Code: Select all
import Things.mymodule as mymoduleelParaguayo wrote:Apologies if I'm missing something. Is Things a subfolder of the folder in which your python script is located?
Why not just add an empty __init__.py file inside Things and then, in your code do:Code: Select all
import Things.mymodule as mymodule
Tried that and it's a very nice solution. I've used...elParaguayo wrote:Apologies if I'm missing something. Is Things a subfolder of the folder in which your python script is located?
Why not just add an empty __init__.py file inside Things and then, in your code do:Code: Select all
import Things.mymodule as mymodule
Code: Select all
from Things import Cheese, Dog, Stone, etc, etc