0

I have a function like this:

def upload_file(request):
    if request.method == 'POST':    
        # session_name = request.POST['session']

        url = request.POST['hostname']

        username = request.POST['username']

        password = request.POST['password']

This function gets the hostname, username and password from a form and store in a respective variable. I want to use the variables url, username and password in another function:

def another_function():
    print url, username, password

What's the right way to do this? I could make upload_file return the variable and use that but I guess it can be done only with one variable.

4

1 回答 1

0

好吧,您可以在函数末尾添加:

    return url, username, password

然后这样做

    url, username, password=upload_file(request)  

像这样,第一个函数返回所有三个变量,之后您可以在另一个函数中使用它们!

于 2013-01-03T12:10:14.927 回答