Python Scripting For Storage Admin Part 4-How To Open Read & Write In File

preview_player
Показать описание
Python: Programming Basics for Absolute Beginners
Python Scripting For Storage Admin - How To Read & Write In File. In this video we will see how we can open a file using python script, then we will write some content in the file and then save it. This is also called as file handling in python script. Below is the code which is explained in above video.
Check out the blog post on file handling in python
# Operation on file. Read and Write.
print(read_file)
Рекомендации по теме
Комментарии
Автор

in this example file1.txt existing one or at the time of run it will created..

jvprasad
Автор

if anyone kindly answer my question. I noticed in the code in this example, in line # 5 there is a "r" . What is the purpose of this "r" ?
I ran the script without this "r" and it worked fine.

1. # Operation on file. Read and Write.
2. s=open("file.txt", "a")
3. s.write("this is a file2\n")
4. s.close()
5. read_file=open("file.txt", "r").read() <=== in this line why is the "r" present
6. print(read_file)

Beyondthedreamofreality