python如何提供要调用给其他人的函数

python如何提供要调用给其他人的函数,python,function,call,Python,Function,Call,我已经写了3个def来使用它,但是我的队友不能调用我的其他函数 def readciscodevice(function, device): conn = sqlite3.connect('server.db') cur = conn.cursor() if device == "switch": cur.execute( "SELECT DISTINCT comman

我已经写了3个def来使用它,但是我的队友不能调用我的其他函数

def readciscodevice(function, device):
        conn = sqlite3.connect('server.db')
        cur = conn.cursor()
        if device == "switch":
                cur.execute(
                        "SELECT DISTINCT command FROM switch WHERE   function =? or function='configure terminal' or function='enable'  ORDER BY key ASC",
                        (function,))
                read = cur.fetchall()
                return read
        elif device == "router":
                cur.execute(
                        "SELECT DISTINCT command FROM router WHERE   function =? or function='configure terminal' or function='enable'  ORDER BY key ASC",
                        (function,))
                read = cur.fetchall()
                return read;
        elif device == "showcommand":
            cur.execute(
                    "SELECT DISTINCT command FROM showcommand WHERE   function =? or  function='enable'  ORDER BY key ASC",
                    (function,))
            read = cur.fetchall()
            return read;


    def get_input():
    a = input("function and params (comma separated):")
    b = input("device:")
    pattern = re.compile('\(.*?\)')

    output_commands = []

    params = a.split(',')

    function = params[0]

    print (params)

    counter = 1
    for result in readciscodevice(function,b):
        command = result[0]
        found_parentheses_list = re.findall(pattern, command)

        output_command = command



        for 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()

for command in commands:
    #do sth, print for example
    print(command)
如果我输入函数和参数,如: fa ip,0,1192.168.0.1255.255.255.0 然后打印出来

['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

但是我不能将我的函数返回给其他队友,这似乎是调用函数的基本问题,有人能解释一下吗?

既然你想以纯文本形式发送函数,你可以这样做

myTestFunction = """
def myTestFunction():
    print('This is a test!')
"""

将函数定义为字符串。然后可以将其作为参数传递。

您能显示实际的代码和调用吗?很难理解你想做什么你将函数返回给其他队友是什么意思?@fdsa,因为我不知道他的程序结构。但这可能不是我们需要解决的问题concern@TommyChan你能举例说明你希望他能做什么吗?很难理解您的问题是什么。@是的,我已经做了。我应该在myTestFunction=?myTestFunction中输入什么?myTestFunction是一个字符串@汤姆尚