Below is my code:
from pathlib import Path
import os
import sys
sys.path.insert(0, os.path.join(Path(__file__).parent.parent.parent.parent,'public'))
import utilities
sys.path.insert(0, Path(__file__).parent.parent)
print(Path(__file__).parent.parent)
import publicmethods
I'm tring to import .py file in special directory. I can import utilities.py
in os.path.join(Path(__file__).parent.parent.parent.parent,'public')
but can't import publicmethods.py
. I'm sure the publicmethods.py
under the Path(__file__).parent.parent
directory.
What's wrong with it? Thanks!
ps: my dir structure like below:
c:\---|--projects|---spider|---public| |---utilities.py|---website|--website|-- publicmethods.py|-- spiders|-- myspider.py
The code about import write in myspider.py