diff --git a/files.html b/files.html index 31c6d32..caf7fa2 100644 --- a/files.html +++ b/files.html @@ -301,7 +301,7 @@ ValueError: zero length field name in format test succeededand again
  1. You start boldly by creating the new file test.log (or overwriting the existing file), and opening the file for writing. The mode='w' parameter means open the file for writing. Yes, that’s all as dangerous as it sounds. I hope you didn’t care about the previous contents of that file (if any), because that data is gone now. -
  2. You can add data to the newly opened file with the write method of the stream object returned by the open() function. After the with block ends, Python automatically closes the file. +
  3. You can add data to the newly opened file with the write() method of the stream object returned by the open() function. After the with block ends, Python automatically closes the file.
  4. That was so fun, let’s do it again. But this time, with mode='a' to append to the file instead of overwriting it. Appending will never harm the existing contents of the file.
  5. Both the original line you wrote and the second line you appended are now in the file test.log. Also note that carriage returns are not included. Since you didn’t write them explicitly to the file either time, the file doesn’t include them. You can write a carriage return with the '\n' character. Since you didn’t do this, everything you wrote to the file ended up on one line.
@@ -452,7 +452,7 @@ PapayaWhip new blacknew blacknew black
  1. The print() statement, in a loop. Nothing surprising here. -
  2. stdout is defined in the sys module, and it is a stream object. Calling its write function will print out whatever string you give it. In fact, this is what the print function really does; it adds a carriage return to the end of the string you’re printing, and calls sys.stdout.write. +
  3. stdout is defined in the sys module, and it is a stream object. Calling its write() function will print out whatever string you give it. In fact, this is what the print function really does; it adds a carriage return to the end of the string you’re printing, and calls sys.stdout.write.
  4. In the simplest case, sys.stdout and sys.stderr send their output to the same place: the Python IDE (if you’re in one), or the terminal (if you’re running Python from the command line). Like standard output, standard error does not add carriage returns for you. If you want carriage returns, you’ll need to write carriage return characters.