Exploring Bioinformatics with Python

Writing to Files

Rough notes.

Open a file for writing with

    outfile = open('name_of_file', 'w')

The 'w' indicates that we're opening the file to write.

Write a string to the file with the write procedure.

    outfile.write(string)

Write a carriage return to the file using the string '\n'.

    outfile.write('\n')

When you are done with a file, close it.

    outfile.close()

This page was generated by Siteweaver on Thu Sep 10 12:23:23 2009.
The source to the page was last modified on Thu Sep 10 10:29:32 2009.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/ExBioPy/writing-files.html.

You may wish to validate this page's HTML

Samuel A. Rebelsky
rebelsky@grinnell.edu