Skip to content

Instantly share code, notes, and snippets.

@Ayon-SSP
Created March 4, 2023 08:38
Show Gist options
  • Save Ayon-SSP/c6ce64060de1d98c7c8846cd89046162 to your computer and use it in GitHub Desktop.
Save Ayon-SSP/c6ce64060de1d98c7c8846cd89046162 to your computer and use it in GitHub Desktop.
Importing Files📁 from different Folder🗃️

Importing Files📁 from different Folder🗃️

Folder structure

GitHub Repo Practical project

Folders
├── Folder1
   ├── subFolder1
       └── File2.py 
   ├── File1.py  
   └── MainFile.py 
└── Folder2
    └── subFolder3
         └── File3.py

Main Folder is Folders Folders -> contains 2 subFolder Name Folder1 & Folder2 Folder1 -> subFolder1 & MainFile.py Folder2 -> subFolder3 -> File3.py subFolder1 -> File1.py & File2.py

To import File from different Folders

1. File in the same directory

MainFile.py

import File1

2. File in the sub directory

MainFile.py

from subFolder1 import File2

3. File in the parent directory

MainFile.py

# You Can use this to import file from any directory
import sys
sys.path.insert(1,'C://Repo//temptodel//Folders//Folder2//subFolder3')

import File3
print(File3.f33)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment