I have python 3.10 project that uses a combination of scraping websites, data analysis, and additional APIs. Some utility modules may be used by the scraping and data analysis modules. I'm fundamentally misunderstanding something about how imports work in Python.
For example, in sl_networking.py
, I try to import the Result
class from result.py
:
from ...util.result import Result
Producing the error:
PS C:\Development\TradeAssist> & c:/Development/TradeAssist/.venv/Scripts/python.exe c:/Development/TradeAssist/libs/scrapers/sl/sl_networking.py
Traceback (most recent call last):
File "c:\Development\TradeAssist\libs\scrapers\sl\sl_networking.py", line 1, in <module>
from ...util.result import Result
ImportError: attempted relative import with no known parent package
The project structure I'm currently using is:
TradeAssist
|__libs
| |__broker_apis
| | |__ibapi
| |__data_analysis
| | |__sl
| | |__ta
| |__scrapers
| | |__sl
| | | | sl_auth.py
| | | |__sl_networking.py
| | |__ta
| |__util
| |__result.py
|__tests
|__test_sl.py
|__test_ta.py
If I have a common utility function that I expect to use within the data_analysis
and scraper
modules, how should I be structuring my project and handling imports?