Beginning Python by Magnus Lie Hetland

Beginning Python by Magnus Lie Hetland

Author:Magnus Lie Hetland
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


In this example, it’s important to note the following: I’ve used print to write to the file. This automatically adds newlines after the strings I supply.

I use sequence unpacking on the opened file, putting each line in a separate variable. (This isn’t exactly common practice because you usually won’t know the number of lines in your file, but it demonstrates the “iterability” of the file object.)

I close the file after having written to it, to ensure that the data is flushed to disk. (As you can see, I haven’t closed it after reading from it. Sloppy, perhaps, but not critical.)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.