Importing modules from parent folder

0 votes

I am running Python 2.5.

This is my folder tree:

ptdraft/
  nib.py
  simulations/
    life/
      life.py

(I also have __init__.py in each folder, omitted here for readability)

How do I import the nib module from inside the life module? I am hoping it is possible to do without tinkering with sys.path.

Note: The main module being run is in the ptdraft folder.

Nov 26, 2020 in Python by anonymous
• 8,910 points
866 views

1 answer to this question.

0 votes

It seems that the problem is not related to the module being in a parent directory or anything like that.

You need to add the directory that contains ptdraft to PYTHONPATH

You said that import nib worked with you, that probably means that you added ptdraft itself (not its parent) to PYTHONPATH.

answered Nov 26, 2020 by Gitika
• 65,910 points

Related Questions In Python

0 votes
1 answer

Importing files from different folder in python.

By default, you can't. When importing a ...READ MORE

answered Dec 20, 2020 in Python by Nikita
3,524 views
0 votes
1 answer

How to resolve the error while importing cv2 from openCV in python?

I would recommend you go with anaconda ...READ MORE

answered Jul 31, 2019 in Python by Mohammad
• 3,230 points
1,667 views
0 votes
1 answer

How to Install Python packages from local file system folder to virtualenv with pip?

Hello @kartik, You can try the code below: pip ...READ MORE

answered May 12, 2020 in Python by Niroj
• 82,880 points

edited Oct 7, 2021 by Sarfaraz 12,650 views
0 votes
1 answer

How to list a column of float values from csv file without importing (Python)

Using the default CSV module Demo: import csv with open(filename, "r") ...READ MORE

answered Sep 16, 2020 in Python by Rajiv
• 8,910 points
8,427 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,409 views
0 votes
3 answers

How to get the return value from a thread using python?

FWIW, the multiprocessing module has a nice interface for ...READ MORE

answered Dec 15, 2020 in Python by Roshni
• 10,520 points
105,133 views
0 votes
4 answers

How do I remove an element from a list by index in Python?

Delete the List and its element: We have ...READ MORE

answered Jun 7, 2020 in Python by sahil
• 580 points
275,958 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP