title: Python - Replacing characters in a list
body: <p>I'm working on a Python script which opens a DBF file, and then from that creates a text output of the contents (either .txt or .csv).</p>
  
  <p>I've now managed to get it writing the output file, but I need to replace the space character in one of the database fields (It's a UK Car registration number, e.g. I need "AB09 CDE" to output as "AB09CDE") but I've been unable to work out how to do this as it seems to be nested lists. The field is rec[7] in the code below.</p>
  
  <pre><code>if __name__ == '__main__':
   import sys, csv
   from cStringIO import StringIO
   from operator import itemgetter
  
   # Read a database
   filename = 'DATABASE.DBF'
   if len(sys.argv) == 2:
       filename = sys.argv[1]
   f = open(filename, 'rb')
   db = list(dbfreader(f))
   f.close()
   fieldnames, fieldspecs, records = db[0], db[1], db[2:]
  
   # Remove some fields that we don't want to use...
   del fieldnames[0:]
   del fieldspecs[0:]
   #Put the relevant data into the temporary table
   records = [rec[7:8] + rec[9:12] + rec[3:4] for rec in records]
  
  
   # Create outputfile
   output_file = 'OUTPUT.txt'
   f = open (output_file, 'wb')
   csv.writer(f).writerows(records)
  </code></pre>
  
  <p>This also adds a lot of spaces to the end of each outputted value. How would I get rid of these?</p>
  
  <p>I'm fairly new to Python so any guidance would be gratefully received!</p>