Companionway

Meeting challenges with success

Taking advantage of *args and **kwargs

Taking Advantage of *args and **kwargs

I consistently forget the option word I have included in a function and so I had to design a way to accept different keywords (option) names to trigger features with in a function.

As an example, assigning a color to a box border is very easy by just adding something like this to a function’s arguments:

def buildabox(msg, border_color="red"):
  """
  docs go here to put a box around msg
  """
  ...

But, if you accidenally call the function like this, it will fail. my_box = buildabox(“my message”, box_color=“white on back”): …


Personal Coding Workflow

Some thoughts on personal coding workflow

My coding is rudimentary at best but the lessons I have learned along the way save me from constant anguish.