Created
June 28, 2016 18:05
-
-
Save charles2588/098e8a81342b65c6efa5c858b4dd91c9 to your computer and use it in GitHub Desktop.
https://repl.it/C6sO/0 created by charles2588
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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