//To read the entire contents
with open("filename.txt") as f:
contents = f.read()
//To read line by line
#!/usr/bin/python
filename = "myfile.txt"
with open( filename ) as f:
# file read can happen here
# print "file exists"
print f.readlines()
with open( filename, "w") as f:
# print "file write happening here"
f.write("write something here ")
No comments:
Post a Comment