repl.it
@charles2588/

FileOperations

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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"))
?