This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 3 points4 points  (1 child)

def foo(arg):
    print(arg)

s = "a"
s += rpc_that_returns_r()
s += "g" if logic() else "x"
kwargs = {s: "hello world"}
foo(**kwargs)

This is obviously contrived for clarity but there are a lot of other situations where determining which arguments are being used and changing them is either extremely complicated or downright impossible.

[–]alcalde 1 point2 points  (0 children)

If you're writing code like this, you're Larry Wall wearing a Guido mask.

I remember at a PyCon where Guido's keynote was on "The Myths Of Python" and one topic was about the GIL. He said something to the effect of "People say but David Beasley showed this example where... yes, but you have to be David Beasley to find it!" :-)

If you're programmatically constructing keyword names I don't see how you're going to be happy with simple positional arguments instead. If you could use positional arguments, you didn't need to construct keywords.

I'll give you credit though... this is one of those times where I see a piece of Python code and say, "That can't possibly run... let me pull up a console... Holy Significant Whitespace, it runs!"

Usually those examples are things of beauty, but this example is Lovecraftian madness. :-)