亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Flask 應用程序超出 Python 最大遞歸深度

Flask 應用程序超出 Python 最大遞歸深度

ibeautiful 2022-11-29 14:52:40
這是錯誤:maximum recursion depth exceeded while calling a Python object我正在使用beautifulsoup解析從中接收到的網頁 HTML,requests然后將解析后的數據存儲到Product類中。該函數通過從 調用一個線程來運行ThreadPoolExecutor()。運行功能:executor = ThreadPoolExecutor()t2 = executor.submit(ScrapePageFull, PageHtml)product = t2.result()ScrapePageFull功能:def ScrapePageFull(data):soup = BeautifulSoup(data)product = Product()# Priceprice = soup.find(DIV, {ID: DATA_METRICS})[ASIN_PRICE]product.price = float(price)# ASINASIN = soup.find(DIV, {ID: DATA_METRICS})[ASIN_ASIN]product.asin = ASIN# Titletitle = soup.find(META, {NAME: TITLE})[CONTENT]product.title = title# Price Stringprice_string = soup.find(SPAN, {ID: PRICE_BLOCK}).textproduct.price_string = price_stringreturn product這是Product課程:class Product:def __init__(self):    self.title = None    self.price = None    self.price_string = None    self.asin = None    pass# Getters@propertydef title(self):    return self.title@propertydef price(self):    return self.price@propertydef asin(self):    return self.asin@propertydef price_string(self):    return self.price_string# [email protected] title(self, title):    self.title = [email protected] price(self, price):    self.price = [email protected] asin(self, asin):    self.asin = asin@price_string.setterdef price_string(self, price_string):    self.price_string = price_string感謝您的幫助,謝謝。
查看完整描述

1 回答

?
慕田峪4524236

TA貢獻1875條經驗 獲得超5個贊

你在這里進入無限遞歸:


@property

def title(self):

    return self.title

返回self.title與再次調用此函數相同,因為定義一個名為的函數title會覆蓋變量self.title。


這也是無限遞歸:


@title.setter

def title(self, title):

    self.title = title

@title.setter將重新定義賦值,比如從這個函數self.title = title中調用。self.title.setter(title)


對于和 也是一樣self.price的。self.price_stringself.asin


要解決此問題,請重命名您的變量:


def __init__(...):

   self._title = None


@property

def title(self):

    return self._title


查看完整回答
反對 回復 2022-11-29
  • 1 回答
  • 0 關注
  • 318 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號