Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python outsource code into class but using parent functions

I am struggling with the basic understanding of classes and esp. inherited classes (if that is a right term).
My child class is supposed to use functions from the parent but super() seems to init the parent class while I want to use their functions directly instead.

What I plan to do:
My program will be a web scrapper. It is supposed to scrap different webpages which always returns the same data structure.
Such use case could be:
Product title will be searched in multiple markets. Amazon.com, Ebay.com, craiglist.com and Aliexpress while each of the pages will give me their cheapest price.

The parent is the selenium class handling the browser, scraping, exceptions etc.
Now for each market I would implement a separate file/class that manages the specific xpath etc to find and pass the command to the parent class to execute.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This would give me for example following file/class structure:

  • Selenium
    • amazon_com
    • ebay_com
    • craiglist_com
    • aliexpress_cn

However each of the sub classes/files like would need the functions of the selenium class.

initially I had one long list of functions within the selenium class. However due an ever growing number of markets to check and constantly changing class names etc. I would much prefer to separate it in several files (potentially ending up in the ball park of 50 sub classes…).

Since I even struggle to explain my problem I believe I have overlooked a very simple solution or missed a design concept entirely. Can someone point me to some good reading source I could use to learn and crack that nut?

>Solution :

To call the function foo on a parent class, you can do super().foo()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading