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 9216193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:21:52+00:00 2026-06-18T02:21:52+00:00

I have a python class (actually its a Google App Engine model) which looks

  • 0

I have a python class (actually its a Google App Engine model) which looks like this:

class MyClass(ParentClass):
    variable_one = PropertyClass(...)
    variable_two = PropertyClass(...)

I intend to build a system which can describe the difference between two instances of this class that represent two versions of the entity at different points in time. Ultimately it would produce a string like

"Variable One changed from 'foo' to 'bar', Variable Two changed from empty to 'baz'"

So, I need to somewhere to store the fact that “variable_one” should be displayed as “Variable One” and so on. Coming from a C# background, my instinct is to use Attributes, for example:

class MyClass : ParentClass
{
    [DisplayName("Variable One")]
    public PropertyClass variable_one;

    [DisplayName("Variable Two")]
    public PropertyClass variable_two;
}

At first, the python equivalent appears to be decorators:

class MyClass(ParentClass):
    @display_name("Variable One")
    variable_one = PropertyClass(...)

    @display_name("Variable Two")
    variable_two = PropertyClass(...)

However, decorators are really doing function currying and as the class variable definition is just assigning an instance of the PropertyClass to variable_one and variable_two it doesn’t look like that would be valid python. In any case, I’m not sure how I’d write that.

One option appears to be to extend the PropertyClass…

class MyClass(ParentClass):
    variable_one = MyPropertyClass("Variable One", ...)
    variable_two = MyPropertyClass("Variable Two", ...)

But there are a few different property classes being used and I want to add one common behaviour to all of them so this seems like too much effort.

I guess I could define a dictionary:

class MyClass(ParentClass):
    variable_one = PropertyClass(...)
    variable_two = PropertyClass(...)
    variable_display_names = {
        "variable_one": "Variable One",
        "variable_two": "Variable Two"
    }

But I’m hoping to hear from some more experienced pythoners about the best most pythonic way of achieving this.

  • 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-18T02:21:53+00:00Added an answer on June 18, 2026 at 2:21 am

    The datastore Property classes are descriptors (like the python @property decorator), but as custom classes that do not implement __setattr__ you can set arbitrary attributes on those objects:

     class MyClass(ParentClass):
         variable_one = PropertyClass(...)
         variable_one.display_name = "Variable One"
    
         variable_two = PropertyClass(...)
         variable_two.display_name = "Variable Two"
    

    which can be generalized to a decorator with:

    def display_name(dispname):
        def decorate_with_display_name(prop):
            prop.display_name = dispname
            return prop
        return decorate_with_display_name
    

    As long as you access the Property via the class (and not the instance) you can retrieve those values again; given an instance you can do print type(instance).variable_two.display_name, for example.

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

Sidebar

Related Questions

I have a model called Customer in google app engine with python: class Customer(db.Model):
So I have some Python code that's structured something like this; class GameObject(pygame.spriteDirtySprite): def
I have a model which has a required string property like the following: class
I have a python class which reads a config file using ConfigParser: Config file:
You have a Python class which needs an equals test. Python should use duck-typing
I have a small Python OOP program in which 2 class, Flan and Outil
I have a conceptual Python design dilemma. Say I have a City class, which
Is this possible in Python? class MyClass(object): @property def property(self): return self._property That is,
I have a Python class C which should have two pseudo- dict s a
I just built my first web app for a class using Google App Engine,

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.