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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:06:18+00:00 2026-05-25T01:06:18+00:00

for example: obj1 = ClassName() obj1.name = name1 obj2 = ClassName() obj2.name = name2

  • 0

for example:

obj1 = ClassName()
obj1.name = "name1"
obj2 = ClassName()
obj2.name = "name2"
obj3 = ClassName()
obj3.name = "name3"
obj4 = ClassName()
obj4.name = "name4"

and we have static variable that return number of objects:
ClassName.counter

How i can get obj1.name, obj2.name and other, but if objects count can be dynamic(using cycle for example) ?

PS: more good if you can say me how to do that in the python, but only design will be good also.

  • 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-05-25T01:06:18+00:00Added an answer on May 25, 2026 at 1:06 am

    Well… it’s actually not recommended to do this type of staff, being a little incomprehensible and prone to bugs…however, you could do it this way:

    class MyClass(object):
        names_list = []
        _name = None
    
        def get_name(self):
            return self._name
        def set_name(self, name):
            assert self._name is None
            self._name = name
            self.names_list.append(name)
        name = property(get_name, set_name)
    
    obj1 = MyClass()
    obj1.name = 'name1'
    
    obj2 = MyClass()
    obj2.name = 'name2'
    
    print obj1.names_list
    print len(obj1.names_list)
    

    It works. It’s ugly. Using some external factory to handle it is probably much better. If you want to store links to existing instances, some array/dictionary with weakrefs would probably be a fine solution.

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

Sidebar

Related Questions

For example: MyClass *obj1 = [[MyClass alloc] init]; MyClass *obj2 = [obj1 retain]; and
I have: class A { public object obj1 {get;set;} public object obj2 {get;set;} public
Example: You have a shortcut s to SomeProgram in the current directory. In cmd.exe
Example I have Person , SpecialPerson , and User . Person and SpecialPerson are
I have a couple of simple objects that have a many-to-many relationship. Django has
example <reference>employee</reference> <data>123</data> how to parse using c# so that i should get employee
I need to create a mutable two-dimensional array in Objective-C. For example I have:
I have to store objects that have two attributes (ida and idb) inside a
I've got a table with three columns, obj1, obj2 (both varchars) and the distance
Example: Class *_obj1; Class *_obj2; void doThis(Class *obj) {} void create() { Class *obj1

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.