Post

PythonPython

H
Harish Harsh

Posted on 25th April 2024|43 views

0
votes

Python Import From Subdirectory

How to import a file from a subdirectory?

I have a file named sample located in my project, I have a subdirectory called lib, including a file called box.py, now I want to import box from sample how can I do this?

 

Answers
P
James ROBERT

Posted on 25th April 2024

Try inserting it inside sys.path like this

sys.path.insert(0, './lib') 

import Box

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos