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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:31:14+00:00 2026-06-18T17:31:14+00:00

So I have the following code, I am trying to add some sort of

  • 0

So I have the following code, I am trying to add some sort of metadata I suppose to an attribute of a class. My idea was that I would have a getter/setter in which the getter would return a float/int/string private variable but return some extra data with it, such as a verbose name.

This works perfectly until I use the setter, which once used seems to ignore the setter and getter.

Does anyone know why what I am doing is not working? Or if there is a better way to go about what I am trying to do?

Many thanks!

class Param(float):
    def __new__(self,name,value):
        return float.__new__(self,value)

    def __init__(self,name,value):
        self.__name = name

    name = property(lambda self: self.__name)


class Beer:
    def __init__(self, temp):
        self.__T = temp

    @property
    def temp(self):
        return Param('Beer Temperature', self.__T)

    @temp.setter
    def temp(self,value):
        self.__T = float(value) 


print b.temp.name, b.temp.__class__

print b.temp * 4.5

print b.temp.name, b.temp.__class__

b.temp = 101

print b.temp.name, b.temp.__class__
  • 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-18T17:31:16+00:00Added an answer on June 18, 2026 at 5:31 pm

    In python 2, properties work properly only with new-style classes (derived from object):

    class Beer(object):
        def __init__(self, temp):
            self.__T = temp
    
        @property
        def temp(self):
            return Param('Beer Temperature', self.__T)
    
        @temp.setter
        def temp(self,value):
            self.__T = float(value) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that I am trying to extract the systems proxy
I have the following code that i am trying to change from a regular
I have the following code sample that im trying to wrap my head around
I have the following bit of code. I'm trying to dynamically add drop-down options
I have the following code that I'm trying to use to populate a ComboBox,
I have the following code trying to add an object to the database: public
I have an html table that I am trying to add some animation to
Ok so I have the following code. I'm trying to output some xml so
I have the following code. I am trying to bind the Command property of
I have the following code, The problem is when I'm trying to assign the

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.