-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserfunction.py
More file actions
79 lines (76 loc) · 2.47 KB
/
userfunction.py
File metadata and controls
79 lines (76 loc) · 2.47 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
78
79
#!/usr/bin/env python3
#Hold the code
lines = []
#Explanations
def cHelp():
print("addCode(change)")
print(" Adds code to your function. Use 3 quotation marks for multi-line things like for or while")
print("")
print("removeCode(index)")
print(" Removes the code at the specied index. Index can be specified as an argument or after it's ran")
print("")
print("printCode()")
print(" Prints all your code. No arguments")
print("")
print("changeCode(change, index)")
print(" Changes the code at the specified index")
print("")
print("runCode()")
print(" Runs your code")
print("")
print("cHelp()")
print(" Prints this screen")
print("")
print("writeOut(fileName,AR)")
print(" Writes your code in a seperate file. AR being an optional argument saying whether you want to append to a file or replace a file.")
print("")
print("Example:")
print('addCode(\'Print("Put down that cookie!")\')')
cHelp()
#Add to the storage
def addCode(change):
lines.append(change)
for anyitem in lines:
print(str(anyitem))
def removeCode(index="NaN"):
codeCopy = line
if index == "NaN":
answer = input("Print current code? (y/n): ")
if answer == "y":
for printNum in range(len(codeCopy)):
print(codeCopy[printNum],"| Index Number:", printNum)
elif answer == "n":
pass
else:
print("Invalid Input")
if index == "NaN":
index = int(input("Which index to remove? "))
print("Line removed: ", lines[int(remNum)])
lines.pop(int(remNum))
def printCode():
for printNum in range(len(lines)):
print(lines[printNum],"| Index Number:", printNum)
def changeCode(change, index):
lines[index] = change
def runCode():
for runLine in lines:
exec(runLine)
def writeOut(fileName, AR="NaN"):
if AR == "NaN":
AR = input("Would you like to append (add to) an existing file or replace an existing file?\n(a/r): ")
if AR.lower() == "a" or AR.lower == "append":
try:
output = open(fileName + ".py", "a")
except:
print("No file found to append to")
elif AR.lower() == "r" or AR.lower == "replace":
try:
output = open(fileName + ".py", "w")
except:
print("An error occured")
else:
print("Invalid response")
return
for line in lines:
output.write(line + "\n")
output.close()