Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
https://repl.it/C6sO/0 created by charles2588
def write2file(filename,content,mode):
try:
with open(filename,mode) as f:
f.write(content)
return("Write Successful")
except IOError:
return("IOError-- "+IOError)
def readfromfile(filename):
try:
with open(filename,"r") as f:
return f.read()
except IOError:
return("No such file exist")
print("Testing 1:-")
print(write2file("abc.txt","My name is abc gonsalves.\n I am so lucky to be in this world.\n i wish i live forever","w"))
print("Testing 2:-" + readfromfile("abc.txt"))
print("Testing 3:- \n" + readfromfile("notexisting.txt"))
print("Testing 4:-")
print(write2file("abc.txt","I love to travel.\n My attempts to learn guitar are on!!!!!","a"))
print("Testing 5:-")
print(write2file("xyz.txt","I love to travel.\n My attempts to learn guitar are on!!!!!","a"))
print("Testing 3:- \n" + readfromfile("xyz.txt"))
Python 3.5.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
Testing 1:-
Write Successful
Testing 2:-My name is abc gonsalves.
I am so lucky to be in this world.
i wish i live forever
Testing 3:-
No such file exist
Testing 4:-
Write Successful
Testing 5:-
Write Successful
Testing 3:-
blahblahI love to travel.
My attempts to learn guitar are on!!!!!I love to travel.
My attempts to learn guitar are on!!!!!
=> None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.