logo-MindMajix
PostPythonPython
H
Harish Harsh

Posted on 22nd July 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?

 

1 answers
Answers
P
James ROBERT

Posted on 22nd July 2024| views

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
Name
Course *
Email *
Phone Number