-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextEditor.py
More file actions
53 lines (51 loc) · 1.24 KB
/
TextEditor.py
File metadata and controls
53 lines (51 loc) · 1.24 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import sys
import shutil
def write():
try:
filename = raw_input("Enter filename")
target = open(filename, "a");
while True:
data = raw_input()
if (data.lower() == "exit"):
break
target.write(data)
target.write("\n")
except Exception as e:
print "Oops, there was a problem" + e
def read():
try:
filename = raw_input("Enter filename")
target = open(filename, "r")
readData = target.read()
print readData
except Exception as e:
print "Oops, there was a problem" + e
def exit():
sys.exit("You are leaving awesome editor! Byee! :)")
def rename():
try:
filename = raw_input("Enter filename")
newName = raw_input("New filename")
shutil.move(filename, newName)
except Exception as e:
print "Oops, there was a problem" + e
def delete():
try:
filename = raw_input("Enter filename")
os.unlink(filename)
except Exception as e:
print "Oops, there was a problem" + e
if __name__ == "__main__" :
print "Option write, read, exit, delete, rename"
input = raw_input("So, what are you wishing to do? ")
if(input.lower() == "write"):
write()
elif(input.lower() == "read") :
read()
elif(input.lower() == "exit"):
exit()
elif(input.lower() == "rename"):
rename()
elif(input.lower() == "delete"):
delete()