0

I have a python function that returns

def edit_user(request):
    error  = False
    errMsg = ""

    id = int(request.POST.get("add_user"))
    if config.editUser(id) != True
        error = True
        errMsg =  _('Failed to edit existing user.')

    return [error, errMsg]

I'm calling this function from another python function.

How do I get these two return values, (error and errMsg) into two separate variables?

4 Answers 4

2

Like this: error, errMsg = edit_user(request).

Sign up to request clarification or add additional context in comments.

Comments

1

Just assign the results to a list or tuple:

error,errMsg = edit_user(...)
(error,errMsg) = edit_user(...)
[error,errMsg] = edit_user(...)

The first syntax is the most preferable.

Comments

0

Hui Zheng is right - error, errMsg = edit_user(request) will do it.

The process is called unpacking and can be used to unpack complicated data structures (see this SO question for another example, and have a look at the python docs for more info).

Comments

0

Just to add to other answers: there's no reason to make a list here at all. Just do this:

return error, errMsg

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.