<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><br><div><div>On Feb 22, 2011, at 2:16 PM, Glen Jarvis wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Vikram,<div>&nbsp;&nbsp; I took another stab at this, sorting the headers and the data by the keys. This makes the columns in the order of the columns:</div><div><div><br></div><div><div>data = (</div><div>&nbsp;&nbsp; &nbsp;{'Protein Name': 'PE2R2_HUMAN', 'gi Number': '38258920', 'etc': 'blah'},</div>
<div>&nbsp;&nbsp; &nbsp;{'Protein Name': 'APAF_HUMAN', 'gi Number': '20141188', 'etc': 'blah2'}</div><div>)</div><div><br></div><div>headers = sorted(data[0].keys())</div><div><br></div></div></div></blockquote><div># ^ reuse....</div><div># use&nbsp;<a href="http://docs.python.org/library/csv.html#csv.DictWriter">http://docs.python.org/library/csv.html#csv.DictWriter</a></div><div><div><div>writer = csv.DictWriter(out, keys)</div><div>for protein in data:</div><div>&nbsp;&nbsp; &nbsp;writer.writerow(protein)</div></div></div><div><br></div><div>Jason</div><div><br></div><blockquote type="cite"><div><div><br></div><div><br></div><div><br></div><div><br></div><br><div class="gmail_quote">
On Tue, Feb 22, 2011 at 1:25 PM, Vikram K <span dir="ltr">&lt;<a href="mailto:kpguy1975@gmail.com">kpguy1975@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">
Consider the following python code which works perfectly:<br><br>fout = open ('1A_out.csv','w')<br><br>writer = csv.writer(fout)<br><br>writer.writerow(('Protein Name','gi Number', 'Peptide', 'Residue',<br>


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Position in Protein', 'length', 'Window''))<br><br>I am writing the values in the csv file using a loop. Everything works fine.<br><br>Now in each row of the csv file i generated i need to append 36 values in 36 separate fields which i have captured in a dictionary data type. Will i have to write out all the extra 36 fields names in the following line or is there some better way?:<br>

<br>writer.writerow(('Protein Name','gi Number', 'Peptide', 'Residue',<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Position in Protein', 'length', 'Window''))<br><br>
<br><br>
<br>_______________________________________________<br>
Baypiggies mailing list<br>
<a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>
To change your subscription options or unsubscribe:<br>
<a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br></blockquote></div><br><br clear="all"><br>-- <br><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse">Things which matter most must never be at the mercy of things which matter least.</span><br>
<br>-- Goethe <br>
</div>
_______________________________________________<br>Baypiggies mailing list<br><a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>To change your subscription options or unsubscribe:<br>http://mail.python.org/mailman/listinfo/baypiggies</blockquote></div><br></div></div></body></html>