Setting property for current class from property in an different class...

Christopher Reimer christopher_reimer at yahoo.com
Thu Sep 7 00:01:41 EDT 2017


On 9/6/2017 7:41 PM, Stefan Ram wrote:

> The following code runs here: 

Your code runs but that's not how I have mine code set up. Here's the 
revised code:


class Requestor(object):
     def __init__(self, user_id, user_name ):
         self._page_start = -1

     @property
     def page_start(self):
         return self._page_start

     @page_start.setter
     def page_start(self, number):
         self._page_start = number



class Scraper(object):
      def __init__(self, user_id, user_name):
          self.requestor = Requestor(user_id, user_name)
      @property
      def page_start(self):
          return self.requestor.page_start
      @page_start.setter
      def page_start(self, number):
          self.requestor.page_start = number

 >>> test = Scraper(1, 1)
 >>> test.page_start
Traceback (most recent call last):
   File "<input>", line 1, in <module>
   File "<input>", line 20, in page_start
AttributeError: 'Requestor' object has no attribute 'page_start'


That's a slightly different error than what I got my code, where the 
Scraper object didn't have the attribute.

Could it be that @property item can't call another @property item?

Thank you,

Chris R.



More information about the Python-list mailing list