File Handling3
(Write Operation on a file
and Standard File Streams)
• Prepared by:
• Prateek Bisht
• MVM Pithoragarh
, Writing onto a file.
• Python provides mainly 2 types of write
functions to write data onto a text file. But
before writing onto a file, the file must be
opened and linked via a file object or file
handle.
• Types of read functions:
write() function
writelines() function
, The write() function.
• Syntax: <FileObject>.write(Str1)
writes the string str1 to the file referenced by
<FileObject>
• Example:
f = open(“Cust.txt”, “w”) # will open file for writing
str = “Welcome to Pyhton”
f.write(str) # will write content of str onto file Cust.txt
f.close()