Python: Handling File I/O – Read/Write Operations


Video is ready, Click Here to View ×

Handling file Input/Output I/O: How to read data from a file and write data to a file in Python

5 thoughts on “Python: Handling File I/O – Read/Write Operations

  1. How do I write onto a document the users input?

    I am creating a program so the user can write their favourite things, I want these to then go onto a file. Here's what I've done:

    def add():
    newFile = open('My Favourite Things','w')
    note = newFile.write(input())
    newFile = open('My Favourite Things','r')

    When I enter something, it prints it back (like it should) in the console. However the file that it creates is empty.
    Thank you in advance for your help 🙂

  2. while using the line[:-1] method i noticed that the last line's last character is removed
    I am getting only rav but i have mentioned rav4 in the text(notepad) file
    Is there any way to fix it?

  3. Hi Joe, I have a file with header section, followed by some formatting and then the data section.. I want to open a file and read lines until I find the header, once the header is found I want to skip few lines to go to the data section and print the contents of data section … how do I do that?

  4. Is doing :-1 like you did to remove the new line in the end more efficient than simply doing rstrip()? I'd assume if it is then it is so because its not calling an explicit string method and instead simply slicing the string…?

  5. No such file or directory: 'inputfile.txt'
    i have some questions.
    why i set a file as inputfile.txt and write down as you teach …but the result show me that No such file or directory: 'inputfile.txt'
    and thx for your video !!!!!!
    best wishes

Leave a Reply

Your email address will not be published. Required fields are marked *