title: Why isn't my file writing method working?
body: <pre><code>import os
  
  books = open(os.path.expanduser("~/Desktop/books.txt")).read()
  b= books.split('\n')
  del b[-1]
  book={}
  for i in b:
      b1=i.split('\t')
      book[b1[0]]=[b1[1],b1[2],b1[3]]
  
  def all_book():
  
      print "The Book List" 
      books = open(os.path.expanduser("~/Desktop/books.txt")) 
      print books.read()
  
  def add_book():
  
      print "Registering New Book"
      books = open(os.path.expanduser("~/Desktop/books.txt"))
      name = raw_input("Title: ") 
      author= raw_input("Author Name: ") 
      publisher =raw_input("Publisher: ") 
      n= int(b1[0])
      n1 = n+1
      newb= [str(n1), '\t', name, '\t', author,'\t', publisher] 
      books.writelines(newb) #Adding file to the list
      newb = {}
      newb[n1]=[name, author, publisher] 
      print 'A New Book Added!' 
      return newb
  
  def del_book():
  
      print "Deleting Books" 
      delnum = str(raw_input("Registered Number:"))
      if delnum in book:
          del book[delnum]
      else:
          print delnum, "Not Found"
  
  
  def show_menu():
  
      print '''
      1) add new
      2) all show
      3) delete
      4) search
      5) Save/out
      '''
      menu_choice = raw_input('what --&gt; ')
      if menu_choice == '1':
              add_book()
      elif menu_choice == '2':
              all_book()
      elif menu_choice == '3':
              del_book()
  
  show_menu()
  </code></pre>