I want to predefine the return value of a function and change it's elements during my function.
So, i.e. let us define
def myFunc()
properties = ["value","num", "comment"]
elements = []
parts = {"properties":properties, "elements":elements}
error = 0
errorMsg = ""
result = [parts, error, errorMsg]
.... # do all the stuff
return result
In case something goes wrong, I would like to change error to an error code and add an error message. If everything went well, elements
will contain some elements.
I understand, why this will always return error=0
. It is because in result
there is not stored a reference to error, there is stored the same reference, that error
has had in the moment when result
was created.
So how can I achieve, that the return value will also be changed, when chaning it's elements?
I know, that
error = [0]
errorMsg = [""]
together with
error[0]=1
errorMsg[0]="error"
works, but in this case, the return value res[1]
is a list and not the value itself.
question from:
https://stackoverflow.com/questions/65941189/python-how-to-create-changeable-return-variable 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…