Monday, 17 June 2019

How do I properly import Python classes?

First, my folder structure is as follows: enter image description here

My BaseScraper.py has:

class BaseScraper:
    def __init__(self, page=0, min_code_size=300):
        self.page = page
        self.MIN_CODE_SIZE = min_code_size
    ...

My JSScraper.py has:

from BaseScraper import BaseScraper


class JSScraper(BaseScraper):
    def __init__(self):
        super(self).__init__(*args)

And my jsscraper.py (that runs it all) has:

from Scraper import JSScraper

scraper = JSScraper.JSScraper(page=0)

So when I run jsscraper.py, I get:

ModuleNotFoundError: No module named 'BaseScraper'

I don't fully get how I'm supposed to structure these projects to properly import and deal with classes. Any assistance would be greatly appreciated.



from How do I properly import Python classes?

No comments:

Post a Comment