PPS Unit 6
PPS Unit 6
https://www.studymedia.in/fe/notes
Unit 6 :File Handling and Dictionaries
Syllabus :
Files: Introduction, File path, Types of files,
Opening and Closing files, Reading and Writing
files. Dictionary method.
Dictionaries- creating, assessing, adding and
updating values.
f = open('d:\\test1.txt ','w+')
f.write("This is the write command")
f.write("\nIt allows us to write in a particular file")
f.write("\n\n\nPython programming")
f.close()
f= open(‘text4.txt’,’r‘)
print(f.readlie())
print(f.readlie())
f.close()
#output
file_object.seek(offset[,whence])
F.seek(0)
Print(‘Now the position of file cursor is:’)
Print(F.tell())
thisdict = dict.fromkeys(x, y)
print(thisdict)
o/p:['key1': 0, 'key2': 0, 'key3': 0]
thisdict = dict.fromkeys(x)
print(thisdict)
O/P:['key1': None, 'key2': None, 'key3': None]
Parameter Description
keyname Required. The keyname of the item
you want to remove
defaultvalue Optional. A value to return if the
specified key do not exist.
car.pop("model")
print(car)
O/p:{'brand': 'Ford', 'year': 1964}