Im trying to get more grip of Classes and also calling different classes to each other which will be more understandable when showing code before:
Utils.py
from proxymanager import ProxyManager # https://pypi.org/project/proxy-manager/
class ProxyServer:
def __init__(self):
self.proxy_manager_test = ProxyManager('./test.txt')
self.proxy_manager_test2 = ProxyManager('./test2.txt')
self.proxy_manager_test3 = ProxyManager('./test3.txt')
self.proxy_manager_test4 = ProxyManager('./test4.txt')
def hello(self):
return self.proxy_manager_test.random_proxy().get_dict()
def world(self):
return self.proxy_manager_test2.random_proxy().get_dict()
def hey(self):
return self.proxy_manager_test3.random_proxy().get_dict()
def yes(self):
return self.proxy_manager_test4.random_proxy().get_dict()
class Testing:
def GetData(self, value=None):
if value:
dataSaved = getattr(ProxyServer(), value)() # <--- Technically works but is it correct way to do it?
print(dataSaved)
Main.py
import random
import time
from .utils import Testing
scraper = Testing()
randomList = ["hello", "world", "hey", "yes"]
while True:
response = scraper.GetData(
value=random.choice(randomList)
)
time.sleep(10)
My concern is the dataSaved = getattr(ProxyServer(), value)() which seem to work as expected but i'm not sure if its correct way to do it, I did get some review about it but the answer I got was that it will technically work but its wrong to do it this way and I want a second opinion from you guys, Is it actually wrong doing it this way?
And please, let me know if I am missing anything else here to provide missing information :)