100 days of code
Day 46:
File I/O(input/output) handling
to open a file : code:
var = open('my_file', 'r')
if we print it it will just print some python objects. To see content write:
var = open('my_file','r') # if we don't use 'r', no error will come beacuse the read mode is default
text = var.read()
print(text)
f.close()
some modes :
1. read(r)
2. write(w, if we make a file in write mode it will automatically create a file and when you run it again it won't throw error)
3. append(a, if we use write it will delete all the text but if we use append it will add text at last)
4. creat(x, wil creat a file and if file is already created it willl throw an error)
5. text(rt, wt, at), used to open the file as a text file
6. binary(rb, wb, ab), used to open files as binary file, we can use this for opening pdf and other documnets
WRITING ON A FILE:
var2 = open('my_file', 'w')
var2.write('yey')
var2.close()
DON'T WANT TO CLOSE:
with open('my_file','w') as f:
f.write('good')
7. Use these: codium, tabnine, amazon code whisper, AI of WPS, Codepen(foe web developers), git and github and gist, stackoverflow, jsfiddle, make own tool
8.
Comments
Post a Comment