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

Started by
1 comment, last by assainator 12 years, 1 month ago
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)?
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.
You could use google.
Second hit provides an answer to your question.
"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

This topic is closed to new replies.

Advertisement