我正在尝试将getItem
和getBuyingType
的返回值分配给函数中__init__
方法中的self
变量。我该怎么做?如果不可能,是否有其他方法将这两个函数的输出指定为Ebay Scraper类的一部分?项目应分配给self.item
和buying_type
分配给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()
您可以在
__init__
方法中调用函数正确的方法是将参数传递给
__init__
以初始化值。如果要提供用于提供这些参数的交互式方法,请定义类方法相关问题 更多 >
编程相关推荐