title: Write dict to file with each key/value pair on a separate line
body: <p>I'm currently in the process of writing an account registration program in Python. The program uses a file called <code>players</code> that has a dictionary written to it with keys corresponding to the player's username, and the other information (email, password, age and gender) as an array associated to the respective key.</p>
  
  <p>The <code>accounts</code> dictionary is defined as so depending on whether or not the <code>players</code> file exists and it is empty.</p>
  
  <pre><code>def is_file_empty(filename):
      return os.stat(filename).st_size == 0
  
  def create_file(filename, mode = 'w'):
      f = open(filename, mode)
      f.close()
  
  if os.path.exists('players'):
      with open('players', 'r') as f:
          if is_file_empty('players'):
              accounts = {}
          else:
              accounts = ast.literal_eval(f.read())
  else:
      create_file('players')
      accounts = {}
  </code></pre>
  
  <p>It is then written to the file using a function inside of a <code>Player</code> class.</p>
  
  <pre><code>def write(self):
          accounts[self.name] = [self.email, self.password, self.age, self.gender]
          with open('players', 'w') as f:
              f.write(accounts)
  </code></pre>
  
  <p>It works fine, however, due to the way it's being written, it always occupies a single line. I want to try writing each key/value pair on its own line within a dictionary, but I have absolutely no idea how to accomplish this.</p>
  
  <p><strong>How can I do so?</strong></p>