-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.py
More file actions
60 lines (51 loc) · 1.73 KB
/
reader.py
File metadata and controls
60 lines (51 loc) · 1.73 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
import os
print(f"\n{" " * 15}WELCOME")
print(f"This is a python CSV analysis tool\n")
print("Note: Pls keep file in same folder with the tool or use full path eg C:/.. when entering file name")
file_Name = str(input("What is the name of the file: "))
can_Read = ""
is_Empty = ""
if not os.path.exists(file_Name):
print("File does not exist. Pls try again")
else:
print("Processing......\n")
if os.path.getsize(file_Name) == 0:
is_Empty = "YES"
else:
is_Empty = "NO"
try:
with open(file_Name, "r") as f:
data = f.read()
can_Read = "YES"
except:
can_Read = "No"
print(f"[File Name: {file_Name}] {" "*5} [Can be read: {can_Read}]{" "*5} [Is Empty: {is_Empty}]\n")
lines = 0
while True:
menu = str(input(f"What would you like to do: Get Started (Y) Quit (Q): ")).lower()
if menu == "q":
print("GoodBye!!")
break
elif menu == "y":
while menu == "y":
with open(file_Name) as file:
print("\n1. Prints the text file to screen")
print("2. Number of Lines")
print("3. Back\n")
menu_2 = int(input("Select: "))
if menu_2 == 1:
for z in file:
print(z)
elif menu_2 == 2:
lines = 0
for i in file:
lines += 1
print(f"There are {lines} lines of text in the file")
elif menu_2 == 3:
break
else:
try:
if menu_2 != 1 or menu_2 != 2 or menu_2 != 3:
print("Error in numbering. Try Again")
except:
print("ok")