title: Create a Python User() class that both creates new users and modifies existing users
body: <p>I'm trying to figure out the best way to create a class that can modify and create new users all in one.  This is what I'm thinking:</p>
  
  <pre><code>class User(object):
  
      def __init__(self,user_id):
        if user_id == -1
            self.new_user = True
        else:
            self.new_user = False
  
            #fetch all records from db about user_id
            self._populateUser() 
  
      def commit(self):
          if self.new_user:
              #Do INSERTs
          else:
              #Do UPDATEs
  
      def delete(self):
          if self.new_user == False:
              return False
  
          #Delete user code here
  
      def _populate(self):
          #Query self.user_id from database and
          #set all instance variables, e.g.
          #self.name = row['name']
  
      def getFullName(self):
          return self.name
  
  #Create a new user
  &gt;&gt;u = User()
  &gt;&gt;u.name = 'Jason Martinez'
  &gt;&gt;u.password = 'linebreak'
  &gt;&gt;u.commit()
  &gt;&gt;print u.getFullName()
  &gt;&gt;Jason Martinez
  
  #Update existing user
  &gt;&gt;u = User(43)
  &gt;&gt;u.name = 'New Name Here'
  &gt;&gt;u.commit()
  &gt;&gt;print u.getFullName()
  &gt;&gt;New Name Here
  </code></pre>
  
  <p>Is this a logical and clean way to do this?  Is there a better way?</p>
  
  <p>Thanks.</p>