Back

Explore Courses Blog Tutorials Interview Questions
+3 votes
3 views
in Python by (3.4k points)
edited by

How can I import the functions from file.py to another Python file which is in:

app/app1/Folder1/xyz.py

from this folder structure:

app/app1/folder1/xyz.py

I've also tried some other methods like one given below, How can I perform this task?

from app.app.folder1.xyz import func_name

2 Answers

0 votes
by (2k points)
edited by

Use sys.path function:

# some_file.py
import sys
sys.path.insert(0, '/path/to/app/app1/xyz')

import file

There are several other methods too but I find this one more easy and efficient. To know more click here.

0 votes
by (106k points)
edited by

Actually, you are doing right just make sure the folder that you want to import must contain an __init__.py, this allows it to be included as a package.

from application.app.folder.file import func_name

You can use the following video tutorials to clear all your doubts:-

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jun 26, 2019 in Python by Anurag (33.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...