Jump to content
  • Advertisement
Sign in to follow this  
gretty

Python Project Architecture: Means I'm Unable to Import Modules

This topic is 2466 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello

I have a problem with my Python project. My project parses different recipe websites for each recipe and writes the recipe data to a text file. I would really appreciate if someone could suggest a way to achieve importing modules from a parent directory because having all the files in the same directory is messy and becomes HUGE very quickly.

My Problem: I cannot import a python file/module that resides in the parent directory. This file contains generic functions that parse webpages. I get an error when I do so: "ValueError: Attempted relative import in non-package"

My solution: I dont know what my solution is? I am thinking I either need to find a way to import a file from the parent directory or to change my project architecture so every domain parsing script sits in the same directory

Project Architecture:
Test Folder:
__init__.py
UtilityFunctions.py # the file I am importing
PerformAllIndexing.py
all_recipes:
__init__.py
index.py # imports ../UtilityFunctions.py
simply_recipes:
__init__.py
index.py # imports ../UtilityFunctions.py


Each subdirectory contains a file called index.py that can extract recipe name, ingredients and directions for a specific website and writes it to a text file.

I encourage you to download my project attached to get a detailed understanding of my problem

Can you tell me what I can do to import a python module from a parent directory or how I can change my project architecture to make this work without having repeating code(the code residing in UtilityFunctions.py)?

Share this post


Link to post
Share on other sites
Advertisement
The only way to do it is to add the parent directory to the module search path. I don't have the details. I read about it in stackoverflow a while ago.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!