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 AssemblyAI tool

Challenge Submission: SpeechCraft - AI-Powered Speech Analysis for Better Communication

SpeechCraft is an advanced real-time speech analytics platform that transforms spoken words into actionable insights. Using cutting-edge AI technology from AssemblyAI, it provides instant transcription while analyzing multiple dimensions of speech performance.

Read full post

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

πŸ‘‹ Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay