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

Related Questions

Programming languages had several (r)evolutionary steps in their history. Some people argue that model-driven
I am doing some maintenance on software and have a problem that I do
I'm starting work on some simulations using MPI and want to do the programming
In the past, and intermittently now, I've used simulation tools like Easy Java Simulations
I have a programming question, as follows, for which my solution does not produce
While programming I have come to an unusual error. When I initialize an integer
I am new to computer programming and have some experience programming with python. I
I have to use C and Fortran together to do some simulations. In their
Are there some practical programming situations for someone to declare a class abstract when
Quite often, in programming we get situations where null checks show up in particularly

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.