DEV Community

Cover image for Importing Files๐Ÿ“ from different Folder๐Ÿ—ƒ๏ธ
AYON KARMAKAR
AYON KARMAKAR

Posted on โ€ข Edited on

8 6 4 4 4

Importing Files๐Ÿ“ from different Folder๐Ÿ—ƒ๏ธ

Folder structure

GitHub Repo Practical project

Folders
โ”œโ”€โ”€ Folder1
โ”‚   โ”œโ”€โ”€ subFolder1
โ”‚   โ”‚    โ””โ”€โ”€ File2.py 
โ”‚   โ”œโ”€โ”€ File1.py  
โ”‚   โ””โ”€โ”€ MainFile.py 
โ””โ”€โ”€ Folder2
    โ””โ”€โ”€ subFolder3
         โ””โ”€โ”€ File3.py
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

2. File in the sub directory

MainFile.py

from subFolder1 import File2
Enter fullscreen mode Exit fullscreen mode

3. File in the 1 step back parent directory

File2.py

from ..MainFile import ClassName
Enter fullscreen mode Exit fullscreen mode

4. 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)
Enter fullscreen mode Exit fullscreen mode

Image of Docusign

๐Ÿ› ๏ธ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

๐Ÿ‘ฅ Ideal for solo developers, teams, and cross-company projects

Learn more