I've written a very tiny script using class to scrape some titles of products from craigslist. My intention is to make use of
__str__() method so that my script can print the result without explicitly calling that very method.
However, when I execute my script in the following way, I get the desired results.
Is this the only way I can print the result or there is anything better to print the result through dunder str method?
import requests from bs4 import BeautifulSoup URL = "http://bangalore.craigslist.co.in/search/rea?s=120" class DataSourcer: def __init__(self,link): self.link = link self.datalist =  def fetch(self): res = requests.get(self.link) soup = BeautifulSoup(res.text,"lxml") for ilink in soup.select("li.result-row a[data-id]"): self.datalist.append(ilink.text) # return self.datalist #I do not wish to return "self.datalist" here def __str__(self): return self.datalist if __name__ == '__main__': crawler = DataSourcer(URL) crawler.fetch() print(crawler.__str__()) #I found it working this way