At one point or another you might come over functions with a lot of arguments. Sometimes it makes sense to combine some of the arguments into super-arguments. I've often done this with dicts, but now I'm looking at better ways of doing it.
I'd like to turn ...
def do_something(ax, ay, az, bu, bv, c):
# Do something
... into ...
def do_something(a, b, c):
# Do something
... where a
and b
contain their subvariations.
One way to do this is to do:
A = namedtuple('A', 'x, y, z')
a = A(ax, ay, az)
B = namedtuple('B', 'u, v')
b = B(bu, bv)
However, this seems simpler:
a = SimpleNamespace(x=ax, y=ay, z=az)
b = SimpleNamespace(u=bu, v=bv)
What is the drawback? The fact that a
and b
aren't well typed? They aren't A and B objects?
(Btw, don't worry about the variable names. I don't normally use as short variable names.)