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

preview_player
Показать описание
Handling file Input/Output I/O: How to read data from a file and write data to a file in Python.

MORE PYTHON FILE I/O

Рекомендации по теме
Комментарии
Автор

wait, so does f1 represents/refer to the file that you opened?

lapnim
Автор

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.close
newFile = open('My Favourite Things', 'r')
print(newFile.read())
add()
add()

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 :)

arctichoundgamer
Автор

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...?

noizfactory
Автор

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?

himanshusoni
Автор

Nice Video. Need help - I have used Pivot function in the script (Python 3.7) and working fine. Now i wanted to save the output to a file or image and then save to power point. (ppt)

paratalsrinivas
Автор

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?

Bangudemeenu
Автор

No such file or directory: 'inputfile.txt'
hello
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

szqpkcn