Class object creation on the fly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nk28
    New Member
    • Jan 2010
    • 26

    #1

    Class object creation on the fly

    Hello all,

    Lets say I have a class and I have stored the number of objects in a file.

    The problem i am facing is that how to create the dynamic number of class objects seeing that I don't know their number and thus can't create directly using

    object_name=cla ss_name(argumen ts)

    Can lambda function be used here????

    Thanxx a lot !!!
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Do you mean instances? You can store instances dynamically in a list. Example:
    Code:
    >>> class Test(object):
    ... 	def __init__(self):
    ... 		pass
    ... 	
    >>> number = 10
    >>> instance_list = []
    >>> for i in range(number):
    ... 	instance_list.append(Test())
    ... 	
    >>>

    Comment

    • nk28
      New Member
      • Jan 2010
      • 26

      #3
      Thanxx a lot...........

      I was looking for this only..... :)

      Comment

      Working...