title: Sorting CSV file with delimiter in Python
body: <p>How to do read a .csv file with the following content</p>
  
  <pre><code>$C=2$A=3$B=1$
  </code></pre>
  
  <p>Then create a new .csv file with the same content but the <code>$</code> changed into <code>,</code> and sorted alphabetically like the following: </p>
  
  <pre><code>A=3,B=1,C=2
  </code></pre>
  
  <p>Thank you!</p>
  
  <p>Edit:</p>
  
  <p>Here's my following code. It ended up giving an extra comma at the beginning of the output.</p>
  
  <pre><code>input = csv.reader(open('inputfile.csv','r'), delimiter='$')
  output = open('outputfile.csv','w')
  try:
      writer = csv.writer(output)
      for column in input:
          writer.writerow(sorted(column))
          print (sorted(column))
  finally:
      out.close()
  </code></pre>
  
  <p>Right now my input is:</p>
  
  <blockquote>
    <p>$C=2$A=3$B=1$</p>
  </blockquote>
  
  <p>and my output is:</p>
  
  <blockquote>
    <p>,A=3,B=1,C=2</p>
  </blockquote>
  
  <p>I want it to be:</p>
  
  <blockquote>
    <p>A=3,B=1,C=2</p>
  </blockquote>
  
  <p>Thanks!</p>