Home » Python

Importing files from different folder in Python

Importing files in Python: Here, we are going to learn how to import files from different folder in Python program?
Submitted by Sapna Deraje Radhakrishna, on December 04, 2019

In order to learn about importing the files from a different folder, assume that the project is having the below folder structure,


In the above structure, there is an __init__.py file added to all the folders. This file ensures that the folder is included as a python package. This file is typically empty, however, we could also add the generic module import statement in this file.

Import files:

Import the files using the syntax from <folder>.<filename> import <module>.


from modules.file import test_method
from modules.sub_module_1.file1 import test1_method

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.