Untitled
unknown
plain_text
3 years ago
1.0 kB
3
Indexable
# Program that will insert a trace statement at the beginning of each function # Name: Anson Vattakunnel # Student Number: VTTANS001 # Date: 4 May 2022 def finder(document): functions = document.read() function = functions.split('\n') for i, line in enumerate(function): if line[:3] == 'def': function_name = line[4:line.find('(')] debuf = ' """DEBUG""";print(' + "'" + function_name + "'" + ')' if i+1 <= len(function): if function[i+1] == debuf: function.pop(i+1) else: function[i] = function[i] + '\n' + debuf if function[0] != '"""DEBUG"""': function[0] = '"""DEBUG"""' + '\n' + function[0] else: function.pop(0) return function print("***** Program Trace Utility *****") filename = input("Enter the name of the program file: \n") with open(filename, 'r') as f: words = finder(f) with open(filename, 'w') as r: str1 = '\n' r.write(str1.join(words))
Editor is loading...