Clear all class variables between instances

This is probably a dumb question, but what's the best way to clear class variables between instances?

I know that I could reset each variable separately in the constructor; but is there a way to do this in bulk?

Or am I doing something completely wrong that requires a different approach? Thanks for helping ...

class User():
    def __init__(self):
        #RESET ALL CLASS VARIABLES

    def commit(self):
        #Commit variables to database

>>u = User()
>>u.name = 'Jason'
>>u.email = 'jason.mendez@yahoo.com.mx'
>>u.commit()

So, every time the user is called, the variables are fresh.

Thank.

+3
source share
4 answers

Can you just pass parameters to a constructor like this?

class User(object):
    def __init__(self, name, email):
        self.name = name
        self.email = email
    def commit(self):
        pass

jason = User('jason', 'jason@email.com')
jack = User('jack', 'jack@yahoo.com')

, , "reset". , . , , , , , User.

def __init__(self):
    self.user = None
    self.email = None
+2

reset , , .

, .

+3

, . , , .

0

This code does not change the attributes nameor emailany of the instances Userexcept u.

0
source

Source: https://habr.com/ru/post/1738412/


All Articles