-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
128 lines (111 loc) · 3.66 KB
/
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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from os import system, name
def clean_word(x):
#Previously, files used to be created as yourname= and it looked very bad. This is just a small cleanup job for making files with names that doesn't have the '=' in it.i.e. just yourname
var = x.split("=")
return var[0]
def clear():
#Found this on the web, not sure exactly what it is doing, but I am importing OS, so i can clear the console when the user types in clear
# for windows
if name == 'nt':
_ = system('cls')
# for mac and linux(here, os.name is 'posix')
else:
_ = system('clear')
def print_list(x):
#This function prints a clean list when requested by the user
try:
var = open(x, "r")
var_read = var.readlines()
if len(var_read) == 1:
print("PrintError: Can't print variable as a list")
return 1
else:
var_clean = []
var_delete = []
var_join = " ".join(var_read)
var_join2 = var_join.split("\n")
for i in var_join2:
if i == "":
var_delete.append(i)
elif i == " list":
var_delete.append(i)
else:
var_clean.append(i)
del var_clean[0]
print(var_clean)
except FileNotFoundError:
print("FileNotFoundError: List was not found")
console()
def print_string(x):
#This function prints a certain variable that gets asked by the user
try:
var = open(x, "r")
var_read = var.readlines()
del var_read[0]
print(var_read)
except FileNotFoundError:
print("FileNotFoundError: String was not found")
console()
def print_var(varname):
'''Prints variable to screen depending on variable type'''
try:
varfile = open(varname[1], "r")
var_read = varfile.readline().rstrip()
if("list" in var_read):
print_list(varname[1])
elif("string" in var_read):
print_string(varname[1])
else:
print("PrintTypeError: The print type given was wrong")
except FileNotFoundError:
print("FileNotFoundError: Variable was not found")
console()
def create_list(varname):
'''This function will create personalized lists, so u can create an infinite amount of lists with any name. It also opens a custom file with the list name and appends the list contents into that file.'''
del varname[0]
varfile = open(clean_word(varname[0]), "w+")
del varname[0]
varname = "".join(varname)
varname = varname.split(",")
varlist = []
for elem in varname:
varlist.append(elem)
varfile.write("list\n")
for count in range(len(varlist)):
varfile.write(varlist[count] + '\n')
varfile.close()
console()
def create_string(varname):
del varname[0]
varfile = open(clean_word(varname[1]), "w+")
del varname[0]
varname = "".join(varname)
varfile.write("string\n")
varfile.write(varname)
varfile.close()
console()
def console():
'''This is the start of the terminal. This is where the code is led back to after every interaction with the terminal.'''
write = input("\n>>> ")
return print_to_console(write)
def print_to_console(x):
'''This is the main function, the will be hadling all the instructions given to the terminal'''
check = x.split(" ")
if "print" in check[0]:
print_var(check)
console()
#This function is really stright forward. Just type helpin the console to get a gauge of everything you can do in this program
elif "help" in check[0]:
print("Here are the list of functions available right now: \nprint ______\nhelp\nlist (insert name)= ______\nstring (insert name)= ______\nclear")
console()
#This is the clear function mentioned above.
elif check[0].lower() == "clear":
clear()
elif check[0].lower() == "string":
create_string(check)
elif check[0].lower() == "list":
create_list(check)
else:
print("FunctionError: Type help to find typeable functions")
console()
console()