File Handling
The write() Method
It writes the contents to the file in the form of
string. It does not return value. Due to buffering,
the string may not actually show up in the file
until the flush() or close() method is called.
The read() Method
It reads the entire file and returns it contents in
the form of a string. Reads at most size bytes or
less if end of file occurs.if size not mentioned
then read the entire file contents.
# write() ,read() Method based program
f = open("cs.txt", 'w')
line1 = 'Welcome to 12th Class Python."
f.write(line1)
line2="\nPython is a general purpose and high level programming language"
f.write(line2)
line3 = "\nReadable and Maintainable Code"
f.write(line3)
line4="\nMultiple Paradigms"
f.write(line4)
line5 = "\nRobust Standard Library"
f.write(line5)
line6="\nSimplify Complex Software Development"
f.write(line6)
f.close()
f = open("cs.txt", 'r')
text = f.read()
print(text)
f.close()
OUTPUT
Welcome to 12th Class Python.
Python is a general purpose and high level programming language
Readable and Maintainable Code
Multiple Paradigms
Robust Standard Library
Simplify Complex Software Development
No comments:
Post a Comment