Python is extremely flexible in terms of both passing and receiving function arguments.
For what you want, the best thing seems to be to make the desired call (in the example case, the "rect") by passing the parameters in a dictionary, instead of typing the name of the parameters in the call. p>
To do this, simply prefix the dictionary with two **
.
That is, in Python, exemplo(a=1, b=2)
is the same as writing:
parametros = {"a":1, "b": 2}; exemplo(**parametros)
.
In the case of a function that passes only parameters that are not None
to a Rect, it is possible to do something like this:
def minha_func(x=None, y=None, centerx=None, centery=None, width=None, height=None):
parametros = {}
for variavel in "x y centerx centery width height".split():
if locals()[variavel] is not None:
parametros[variavel] = locals()[variavel]
meu_rect = pygame.Rect(**parametros)