Python Forum
Link scripts from a different folder
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Link scripts from a different folder
#1
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.
Reply
#2
shouldn't it look like this?

from Databases.UserDatabase import *
from Functions.CreateItemsTable import createDatabase
from Functions.AddInventory import addInventory
Reply
#3
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?
Reply
#4
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 *
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 525 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,471 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  How to run an exe file in the Scripts folder using py.exe? quazirfan 2 2,943 Sep-08-2021, 01:00 AM
Last Post: quazirfan
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 2,466 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  Python Cut/Copy paste file from folder to another folder rdDrp 4 5,037 Aug-19-2020, 12:40 PM
Last Post: rdDrp
  Delete directories in folder is not working after folder is updated asheru93 2 2,646 Feb-13-2019, 12:37 PM
Last Post: asheru93
  copy content of folder to existing folder shlomi27 0 2,630 Aug-11-2018, 01:44 PM
Last Post: shlomi27
  How to link two python scripts berthenet 35 74,298 Feb-03-2018, 02:24 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020