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 ④
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.
-write method of the stream object returned by the open() function. After the with block ends, Python automatically closes the file.
+write() method of the stream object returned by the open() function. After the with block ends, Python automatically closes the file.
mode='a' to append to the file instead of overwriting it. Appending will never harm the existing contents of 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.
print() statement, in a loop. Nothing surprising here.
-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.
+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.
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.