Skip to content

Commit a441b75

Browse files
authored
Merge pull request #231 from knakaj/issue#229
fixes #229
2 parents 9f602f0 + 94aef2c commit a441b75

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

pretext/Files/WritingTextFiles.ptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<section xml:id="files_writing-text-files">
33
<title>Writing Text Files</title>
4-
<p>One of the most commonly performed data processing tasks is to read data from a file, manipulate it in some way, and then write the resulting data out to a new data file to be used for other purposes later. To accomplish this, the <c>open</c> function discussed above can also be used to create a new file prepared for writing. Note in <xref ref="files_intro--workingwith-data-files"/> above that the only difference between opening a file for writing and opening a file for reading is the use of the <c>'w'</c> flag instead of the <c>'r'</c> flag as the second parameter. When we open a file for writing, a new, empty file with that name is created and made ready to accept our data. As before, the function returns a reference to the new file object.</p>
4+
<p>One of the most commonly performed data processing tasks is to read data from a file, manipulate it in some way, and then write the resulting data out to a new data file to be used for other purposes later. To accomplish this, the <c>open</c> function discussed above can also be used to create a new file prepared for writing. Note in <xref ref="files_working-with-data-files"/> above that the only difference between opening a file for writing and opening a file for reading is the use of the <c>'w'</c> flag instead of the <c>'r'</c> flag as the second parameter. When we open a file for writing, a new, empty file with that name is created and made ready to accept our data. As before, the function returns a reference to the new file object.</p>
55
<p><xref ref="files_alternative-file-reading-methods"/> above shows one additional file method that we have not used thus far. The <c>write</c> method allows us to add data to a text file. Recall that text files contain sequences of characters. We usually think of these character sequences as being the lines of the file where each line ends with the newline <c>\n</c> character. Be very careful to notice that the <c>write</c> method takes one parameter, a string. When invoked, the characters of the string will be added to the end of the file. This means that it is the programmers job to include the newline characters as part of the string if desired.</p>
66
<p>As an example, consider the <c>ccdata.txt</c> file once again. Assume that we have been asked to provide
77
a file consisting of only the global emission and the year of this climate change. In addition, the year

0 commit comments

Comments
 (0)