kinto-d kinto-d - 1 year ago 80
Python Question

How to recreate / reinstantiate an object in python 2.7

I am looking for a way to recreate / reinstantiate an object in python, because I want the object to have a default attribute in each loop.

for case in all_case:

# i want in each loop it's create a new object / reinstantiate it
pda = PushDownAutomata()
print pda.evaluate(case, debug=False)

# already add "del pda" but it's not working

How can I achieve it?

Answer Source

Note that class attributes are not the same as instance attributes. for example:

class A(object):

    a = None # this is a class attribute

    def __init__(self, b):
        self.b = b # b is an instance attribute
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download