Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8562595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:45:48+00:00 2026-06-11T16:45:48+00:00

I’m trying to use the property decorator in a Class. While it works well

  • 0

I’m trying to use the property decorator in a Class. While it works well per se, I can’t use any code that has to access the REQUEST.

class SomeClass():
   #Zope magic code
   _properties=({'id':'someValue', 'type':'ustring', 'mode':'r'},)

  def get_someValue(self):
    return self.REQUEST

  @property
  def someValue(self):
    return self.REQUEST

Although calling get_someValue gets me the desired result, trying to access someValue raises an AttributeError.

What’s the logic behind this behaviour? Is there a way to get around this limitation?

(I’m using Zope 2.13.16, Python 2.7.3)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:45:49+00:00Added an answer on June 11, 2026 at 4:45 pm

    The property decorator only works with new-style classes; that is to say, classes that inherit from object. Acquisition (which gives you access to the global REQUEST object via attribute access) on the other hand is very much ‘old-skool’ python and the two do not work well together, as property ignores acquisition wrappers, which are needed to acquire the REQUEST object.

    Zope has it’s own property-like method that pre-dates new-style classes and the property decorater, called ComputedAttribute, which actually predates the property decorator and new-style classes by many years. A ComputedAttribute-wrapped function does know how to behave with an Acquisition-wrapped object, though.

    You can use ComputedAttibute much like the property decorator:

    from ComputedAttribute import ComputedAttribute
    
    class SomeClass():   
        @ComputedAttribute
        def someProperty(self):
            return 'somevalue'
    

    The ComputedAttribute wrapper function also can be configured with a level of wrapping, which is what we need when dealing with Acquisition wrappers. You cannot use the ComputedAttribute as a decorator in that case:

    class SomeClass():   
        def someValue(self):
            return self.REQUEST
        someValue = ComputedAttribute(someValue, 1)
    

    It is easy enough to define a new function to do the decorating for us though:

    from ComputedAttribute import ComputedAttribute
    
    def computed_attribute_decorator(level=0):
        def computed_attribute_wrapper(func):
            return ComputedAttribute(func, level)
        return computed_attribute_wrapper
    

    Stick this in a utility module somewhere, after which you can then use it as a callable decorator to mark something as an Acquisition-aware property:

    class SomeClass(): 
        @computed_attribute_decorator(level=1)
        def someValue(self):
            return self.REQUEST
    

    Note that unlike property, ComputedAttribute can only be used for getters; there is no support for setters or deleters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.