File Handling
File Handling
10. r+, rb+(r+b) modes will enable the user to read and also
write contents to file if file is already created. If file is not
created then it will not be able create the file
11. w+, wb+(w+b) will enable the user to read and write
contents. If file does not exist it will create a file and also can
read contents from file
12. a+, ab+(a+b) will enable the user to append contents to file
if file is not existing it will create and write and also user can
read content from the file.
The same rules are applicable to binary also.
For reading and writing the text file
13. For writing contents to files we have 2 functions
Write (st) for writing the string
Writelines(list) takes list as a parameter
while True:
try:
r=pickle.load(f)
print(r)
except EOFError:
break
19. file can be opened in the following manner using with block.
This will automatically close the file . it does not require to
explicitly closing of the file.
with open("cloth.dat","rb")as f:
while True:
try:
r=pickle.load(f)
print(r)
except EOFError:
break
Absolute path:- the path from the root drive to the present
directory in which the required file is existing.
Relative path:-This path is relative to the current working
directory.
. is for current working directory
..\-one step back.