title: Using a variable to open a text file in Python
body: <p>Is it possible to use a variable (such as username) to open a text file that is named based on that variable. For example, in the following program, the file is called "Username1", and I want it to append details to it, IF it exists. In the below situation, I am using the actual username (username1), but I want it to be able to insert the username (which is a variable) there instead.</p>
  
  <pre><code>#Open Writer to append to file
  with open("username1.txt","a") as membersfile:
      membersfileWriter=csv.writer(membersfile)
      membersfileWriter.writerow([viewedlist])
  </code></pre>
  
  <p>THe username, in this program is passed to this particular function as a parameter:</p>
  
  <pre><code>def viewfilmfunction(x,username):
  </code></pre>