Not sure if this is what you are looking for.
Below a script with with you can change name, digit and operator of functions by their index (0 = first function).
In the head of the script, you set a list of tuples with the desired settings, like:
[(index, ("NewName"), ("digit"), ("operator")), (index, ("NewName"), ("digit"), ("operator"))]
You can pick any index you'd like to change. If one or more of the properties do not need to be changed, leave the tuple empty.
Example: to only change the name of the function with index 2 (the third function, since 0 = the first):
[(2, ("NewName"), (), ())]
To change the first two functions:
changes = [(0, ("FuncName1"), ("2"), ("+")), (1, ("FuncName2"), ("2"), ("**"))]
Keeping different sets of functions
This script could be mainly of use if you keep different sets of function properties by keeping different changes =
lines, and commenting out all except the one you currently need for example.
How to use
Copy the script below into an empty file, set the desired parameters for the functions to change, the path to the file, save it as script.py and run it by:
python3 /path/to/script.py
The script:
#!/usr/bin/env python3
# function / name / digit / operator
# (example)
changes = [(0, ("Name1"), (), ()), (1, ("Name2"), ("2"), ("**"))]
subject_file = "/path/to/file_withfunctions"
operators = ["+", "-", "*"] # ** has been taken care of in the script, you can use it in the "changes" line
with open(subject_file) as sample:
lines = [line for line in sample.readlines()]
def first_occurrence(index, string, lines):
area = lines[index:]
func_line = [[i, area[i]] for i in range(len(area))if string in area[i]][0]
func_line[0] = func_line[0]+index
return func_line
functiondata = [[[i, lines[i]],first_occurrence(i, "==", lines)] for i in range(len(lines)) if "[" in lines[i]]
for item in changes:
subject = functiondata[item[0]]
if len(item[1]) != 0: # name
name = subject[0][1].split()[0]
newname = item[1]
lines[subject[0][0]] = lines[subject[0][0]].replace(name, newname)
if len(item[2]) != 0: # digit
or_line = subject[1][1]
character = [ch for ch in or_line if ch.isdigit()][0]
new_line = or_line.replace(character, item[2])
lines[subject[1][0]] = new_line
if len(item[3]) != 0: # operator
or_line = new_line
if "**" in or_line:
new_line = or_line.replace("**", item[3])
else:
character = [ch for ch in operators if ch in or_line][0]
lines[subject[1][0]] = new_line
new_line = or_line.replace(character, item[3])
lines[subject[1][0]] = new_line
with open(subject_file, "wt") as sample:
for line in lines:
sample.write(line)