I often have statements in my code that do the following:
long_descriptive_variable_name = some_function(long_descriptive_variable_name)
which is very clear, but verbose and somewhat redundant at the same time. Is there any way in Python to simplify this statement perhaps by making some_function
act as a "mutating" ("in-place") function?
For example, in Julia one can often do the following:
some_function!(long_descriptive_variable_name)
and this is dispatched to the version of some_function
that writes directly to long_descriptive_variable_name
, effectively updating the variable.
Is there any way to concisely express the same in Python for a generic function some_function
?
What about doing the same with a general object method? i.e. simplifiying
long_variable_name = long_variable_name.method(arg1, arg2)
If the above is not (easily) doable with current versions of Python, are there any PEPs considering this change in the near future?
global
variable inside your function and assign the return result to that. – Spot