i have write 3 def use cant called other function teammate.
def readciscodevice(function, device): conn = sqlite3.connect('server.db') cur = conn.cursor() if device == "switch": cur.execute( "select distinct command switch function =? or function='configure terminal' or function='enable' order key asc", (function,)) read = cur.fetchall() return read elif device == "router": cur.execute( "select distinct command router function =? or function='configure terminal' or function='enable' order key asc", (function,)) read = cur.fetchall() return read; elif device == "showcommand": cur.execute( "select distinct command showcommand function =? or function='enable' order key asc", (function,)) read = cur.fetchall() return read; def get_input(): = input("function , params (comma separated):") b = input("device:") pattern = re.compile('\(.*?\)') output_commands = [] params = a.split(',') function = params[0] print (params) counter = 1 result in readciscodevice(function,b): command = result[0] found_parentheses_list = re.findall(pattern, command) output_command = command i, param_placeholder in enumerate(found_parentheses_list): param = params[counter] output_command = re.sub(pattern, param, output_command, count=1) counter +=1 output_commands.append(output_command) # input_para(a,b) return output_commands # def input_para(a,b): # print(a,b) # other program calls: commands = get_input() command in commands: #do sth, print example print(command)
if input function , paraneter like: fa ip,0,1,192.168.0.1,255.255.255.0 , prints out
['fa ip', '0', '1', '192.168.0.1', '255.255.255.0'] enable configure terminal interface fa0/1 ip address 192.168.0.1 255.255.255.0 no shutdown
but cannot return function other teammate, seems basic call function problem, explain ?
since want send function plain-text, can this.
mytestfunction = """ def mytestfunction(): print('this test!') """
defining function string. can pass argument.