Working with files | More Python for Beginners [14 of 20]

Play Working with files | More Python for Beginners [14 of 20]

The Discussion

  • User profile image
    feitosaneto
    Why is a beginner supposed to know what is a "lorem ipsum file"?
  • User profile image
    feitosaneto
    it is funny that writelines() does not in fact write lines, as print() does on the screen.

    And the instructor even shows code that uses write() to write a certain "\n" and the line even has a comment: "Write a new line". So you use write() to write a line, but you can use writelines() to write a list of strings, but in the SAME line.

    And it is ok: if you want to writelines() to write lines from the strings you just call join() on the strings and insert a '\n' between each string! I believe it is in the next video.

    funny indeed
  • User profile image
    feitosaneto
    6:36 Manage the stream

    For a beginner this probably will make no sense. You forgot to tell about the existence of a buffer. You can bet a beginner will not understand why flush() is not needed for each write() because you did not said the system will write the bytes to disk right away by itself.

    The difference and "right away" and "done" in general is not important and the system as a whole runs much faster.

    Probably you should mention that the system has intermediate areas in memory for optimize disk access, the so called buffers, and that you only need flush() when you want to be sure that the data will go to disk. And in this case your example on someone else opening the same file and seeing the same data was on spot.

    bufsize or something similar appeared on a slide I believe in the previous video, but you said nothing about it. This is the size of the intermediate area the system reserves for each stream, and a write() writes to this area. When the buffer is full, or the file is closed, or the system chooses to, the contents of the buffer are written to disk. It is called flush()

Add Your 2 Cents

More episodes in this series

Related episodes