|
| 1 | +#!/usr/bin/env python3 |
| 2 | +#Hold the code |
| 3 | +lines = [] |
| 4 | + |
| 5 | +#Explanations |
| 6 | +def cHelp(): |
| 7 | + print("addCode(change)") |
| 8 | + print(" Adds code to your function. Use 3 quotation marks for multi-line things like for or while") |
| 9 | + print("") |
| 10 | + print("removeCode(index)") |
| 11 | + print(" Removes the code at the specied index. Index can be specified as an argument or after it's ran") |
| 12 | + print("") |
| 13 | + print("printCode()") |
| 14 | + print(" Prints all your code. No arguments") |
| 15 | + print("") |
| 16 | + print("changeCode(change, index)") |
| 17 | + print(" Changes the code at the specified index") |
| 18 | + print("") |
| 19 | + print("runCode()") |
| 20 | + print(" Runs your code") |
| 21 | + print("") |
| 22 | + print("cHelp()") |
| 23 | + print(" Prints this screen") |
| 24 | + print("") |
| 25 | + print("writeOut(fileName,AR)") |
| 26 | + 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.") |
| 27 | + print("") |
| 28 | + print("Example:") |
| 29 | + print('addCode(\'Print("Put down that cookie!")\')') |
| 30 | +cHelp() |
| 31 | +#Add to the storage |
| 32 | +def addCode(change): |
| 33 | + lines.append(change) |
| 34 | + for anyitem in lines: |
| 35 | + print(str(anyitem)) |
| 36 | + |
| 37 | +def removeCode(index="NaN"): |
| 38 | + codeCopy = line |
| 39 | + if index == "NaN": |
| 40 | + answer = input("Print current code? (y/n): ") |
| 41 | + if answer == "y": |
| 42 | + for printNum in range(len(codeCopy)): |
| 43 | + print(codeCopy[printNum],"| Index Number:", printNum) |
| 44 | + elif answer == "n": |
| 45 | + pass |
| 46 | + else: |
| 47 | + print("Invalid Input") |
| 48 | + if index == "NaN": |
| 49 | + index = int(input("Which index to remove? ")) |
| 50 | + print("Line removed: ", lines[int(remNum)]) |
| 51 | + lines.pop(int(remNum)) |
| 52 | + |
| 53 | +def printCode(): |
| 54 | + for printNum in range(len(lines)): |
| 55 | + print(lines[printNum],"| Index Number:", printNum) |
| 56 | +def changeCode(change, index): |
| 57 | + lines[index] = change |
| 58 | +def runCode(): |
| 59 | + for runLine in lines: |
| 60 | + exec(runLine) |
| 61 | +def writeOut(fileName, AR="NaN"): |
| 62 | + if AR == "NaN": |
| 63 | + AR = input("Would you like to append (add to) an existing file or replace an existing file?\n(a/r): ") |
| 64 | + if AR.lower() == "a" or AR.lower == "append": |
| 65 | + try: |
| 66 | + output = open(fileName + ".py", "a") |
| 67 | + except: |
| 68 | + print("No file found to append to") |
| 69 | + elif AR.lower() == "r" or AR.lower == "replace": |
| 70 | + try: |
| 71 | + output = open(fileName + ".py", "w") |
| 72 | + except: |
| 73 | + print("An error occured") |
| 74 | + else: |
| 75 | + print("Invalid response") |
| 76 | + return |
| 77 | + for line in lines: |
| 78 | + output.write(line + "\n") |
| 79 | + output.close() |
0 commit comments