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

  • Home
  • SEARCH
  • 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 105737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:29:11+00:00 2026-05-11T01:29:11+00:00

I am programming a simulations for single neurons. Therefore I have to handle a

  • 0

I am programming a simulations for single neurons. Therefore I have to handle a lot of Parameters. Now the Idea is that I have two classes, one for a SingleParameter and a Collection of parameters. I use property() to access the parameter value easy and to make the code more readable. This works perfect for a sinlge parameter but I don’t know how to implement it for the collection as I want to name the property in Collection after the SingleParameter. Here an example:

class SingleParameter(object):   def __init__(self, name, default_value=0, unit='not specified'):     self.name = name     self.default_value = default_value     self.unit = unit     self.set(default_value)   def get(self):     return self._v   def set(self, value):     self._v = value   v = property(fget=get, fset=set, doc='value of parameter')  par1 = SingleParameter(name='par1', default_value=10, unit='mV') par2 = SingleParameter(name='par2', default_value=20, unit='mA')  # par1 and par2 I can access perfectly via 'p1.v = ...' # or get its value with 'p1.v'  class Collection(object):   def __init__(self):     self.dict = {}   def __getitem__(self, name):     return self.dict[name] # get the whole object     # to get the value instead:     # return self.dict[name].v   def add(self, parameter):     self.dict[parameter.name] = parameter     # now comes the part that I don't know how to implement with property():     # It shoule be something like     # self.__dict__[parameter.name] = property(...) ?  col = Collection() col.add(par1) col.add(par2) col['par1'] # gives the whole object  # Now here is what I would like to get: # col.par1 -> should result like col['par1'].v # col.par1 = 5 -> should result like col['par1'].v = 5 

Other questions that I put to understand property():

  • Why do managed attributes just work for class attributes and not for instance attributes in python?
  • How can I assign a new class attribute via __dict__ in python?
  • 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. 2026-05-11T01:29:11+00:00Added an answer on May 11, 2026 at 1:29 am

    Using the same get/set functions for both classes forces you into an ugly hack with the argument list. Very sketchy, this is how I would do it:

    In class SingleParameter, define get and set as usual:

    def get(self):   return self._s def set(self, value):   self._s = value 

    In class Collection, you cannot know the information until you create the property, so you define the metaset/metaget function and particularize them only later with a lambda function:

    def metaget(self, par):   return par.s def metaset(self, value, par):   par.s = value def add(self, par):   self[par.name] = par   setattr(Collection, par.name,     property(       fget=lambda x : Collection.metaget(x, par),       fset=lambda x, y : Collection.metaset(x,y, par)) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 136k
  • Answers 136k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer So I resolved this issue by removing one of the… May 12, 2026 at 7:13 am
  • Editorial Team
    Editorial Team added an answer A combination of the following fixed the issue: Better screen… May 12, 2026 at 7:13 am
  • Editorial Team
    Editorial Team added an answer The XDocument represents the whole document, not the root node.… May 12, 2026 at 7:13 am

Related Questions

I need to make an application for creating logic circuits and seeing the results.
I am working through some of the exercises in The C++ Programming Language by
What are some good tips and/or techniques for optimizing and improving the performance of
I hear a lot of people talking about the revolution that is coming in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.