-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomework7.py
More file actions
77 lines (64 loc) · 2.08 KB
/
Homework7.py
File metadata and controls
77 lines (64 loc) · 2.08 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os.path
def check(name):
if os.path.exists(name+".txt"):
print ("File exist")
fileexist(name)
else:
print ("File not exist")
createfile()
def createfile():
name= input("Please Enter the Title of the File you want to Create\n ")
openfile=open(name+".txt","w+")
add= input("Please Enter the information you want to put in the File\n")
openfile.write(add+"\n")
openfile.close()
fileexist(name)
def update(name):
present= input("Please Enter the information you want to store:\n")
linenum= int(input("Please Enter the Line you want the information to store:\n") )
with open(name+".txt","r") as openfile:
data = openfile.readlines()
print(data)
data[linenum-1]=present
change=open(name+".txt","w")
change.writelines(data)
change.close()
end()
def fileexist(n):
l=1
while(l==1):
response= input("Please input what actions you want to perform with this file\nA. Read the File\nB. Delete the file and Start Over\nC. Append the File\nD. Replace a Single Line\n").lower()
if response == "a":
openfile= open(n+".txt","r")
print(openfile.read())
l=0
openfile.close()
end()
if response == "b":
cwd= os.getcwd()
file_path = cwd+"\\"+n+".txt"
os.remove(file_path)
createfile()
l=0
if response == "c":
openfile= open(n+".txt","a")
l=0
if response == "d":
l=0
update(n)
else:
print(" The inputted character was incorrect. Please try again.")
add= input("Please Enter the information you want to put in the File\n")
openfile.write(add+"\n")
openfile.close()
end()
def main():
filename= input("Please Enter the Filename\n")
check(filename)
def end():
response= input("Do you want to Exit? YES or NO\n").lower()
if response !="yes":
main()
else:
return exit()
main()