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
  • 32,567
  • 20
  • 113
  • 146
Marco Dinatsoli
  • 10,322
  • 37
  • 139
  • 253

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,416
  • 2
  • 41
  • 58