0

I have this hierarchy:

myfile.py
Spider
----__init__.py
----spiders
----------------file.py

and the file.py contains class myClass

I used to do this inside the myfile.py

from Spider.spiders.file import myClass

now I changed my hierarchy, and I put myfile.py inside a folder named newFolder, so the new hierarchy is:

newFolder
------myfile.py
Spider
----__init__.py
----spiders
----------------file.py

and I changed the path as this:

from ... import Spider.spiders.file.myClass

but I got invalid syntax in the spiders.spiders

help please

smci
  • 29,564
  • 18
  • 109
  • 144
Marco Dinatsoli
  • 9,834
  • 34
  • 124
  • 238

1 Answers1

2

In from <a> import <b> syntax you should specify module path before import: from <a>.<b> import <c>:

from ...Spider.spiders.file import myClass

You can also add parent directory to path:

import sys
sys.path.append("..")
from Spider.spiders.file import myClass
Daniil Ryzhkov
  • 7,084
  • 2
  • 39
  • 56