Python Forum
Link scripts from a different folder - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Link scripts from a different folder (/thread-37199.html)



Link scripts from a different folder - Extra - May-11-2022

Hello,

I have a folder called "Inventory system" and within the "Inventory System" folder I have 2 subfolders: "Databases" and "Functions"

The "Databases" stores my .db files and the "Functions" folder stores all the functions that I call in my main script (My main script is located in the "Inventory System" folder).

I'm wondering if it's possible for my main script to call all those files from those different folders. I know I need an import statement, but where/how do I provide the paths for the folders?

My Main.py import statements:
#-----------------------------------------------
from /Databases/UserDatabase import *
from /Functions/CreateItemsTable import createDatabase
from /Functions/AddInventory import addInventory
#---------------------------------------------------------------
And how would I connect to the inventory.db since it's in the "Databases" folder and this chunk of code is from one of my Functions (located in the "Functions" folder)
    #Connect to the inventory database (inventory.db)
    connection = sqlite3.connect("inventory.db")
    cursor = connection.cursor()
Thanks in advance.


RE: Link scripts from a different folder - Axel_Erfurt - May-11-2022

shouldn't it look like this?

from Databases.UserDatabase import *
from Functions.CreateItemsTable import createDatabase
from Functions.AddInventory import addInventory



RE: Link scripts from a different folder - Extra - May-11-2022

Awesome, Thanks. That's a lot simpler than what I had expected.

Now is there a way to call the inventory.db file from the "Databases" folder to my other scripts in the "Functions" folder.

Is this even possible?


RE: Link scripts from a different folder - snippsat - May-11-2022

You most look at how Packages work.
Here a post of some examples that i written before.

As mention should not have / in import statement,it is ..
No *💀
from /Databases/UserDatabase import *