-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunction_IO.py
32 lines (27 loc) · 955 Bytes
/
Function_IO.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
27
28
29
30
31
32
def Open(file):
try:
result = open(file, "r") # If file exists then it will find it however if it doesn't then it will create the file
for line in result.readlines():
print(line + "\n")
result.close() #The result object is huge in size so have to close everytime we open it as the
except ValueError as msg:
print ("Error: Only one operation able run.", msg)
except FileExistsError as errmsg:
print("Error: file exists already", errmsg)
except FileNotFoundError as errmsg:
print("Error: can't find the file", errmsg)
else:
print("File found successfully")
Open(".Order.txt")
def Write(file):
try:
result = open(file, "a")
result.write("Hello")
for line in result.readlines():
print(line)
result.close()
except:
pass
else:
print("Written on file successfully")
Write(".Order.txt")