I am trying to assign the return values of getItem and getBuyingType to the self variables in the __init__ method in my Ebay Scraper function. How can I do this? If it's not possible, is there another way to assign the outputs of these two functions to be part of the Ebay Scraper class? Item should be assigned to self.item and buying_type to self.buying_type.
class EbayScraper(object): def __init__(self): self.base_url = "https://www.ebay.com/sch/i.html?_nkw=" self.item = self.buying_type = self.url_seperator = "&_sop=12&rt=nc&LH_" self.url_seperator2 = "&_pgn=" self.page_num = "1" self.currentPage = 1 def getItem(self): item = input("Item: ") return item def getBuyingType(self): buying_type = input("Please specify a buying type (Auction or Buy It Now): ") buying_type = buying_type.lower() if buying_type == "auction": return buying_type + "=1" elif buying_type == "buy it now": return buying_type + "=1" else: print("Invalid buying type specified.") self.getBuyingType()
self.item = self.getItem()?getBuyingTyperecursively when you should just be using a loop instead.EbayScraperto prompt the user for input; that's the responsibility of whoever is usingEbayScraper. At most, you should define a method that simply takes an argument and assigns that toself.item, or just assign to the attribute directly; getters aren't always necessary in Python.