Help with changes in traceback stack from Python 2.7 to Python 3.x

Chris Angelico rosuav at gmail.com
Mon Apr 28 18:41:30 EDT 2014


On Tue, Apr 29, 2014 at 5:50 AM, Andrew Konstantaras <akonsta at icloud.com> wrote:
> Actually, that is one of the nice features of using a dictionary, I can
> check if the key is there and if it is pull it out.  As I was dusting off
> this old code, I considered trying to implement this functionality through
> by creating a class.  I never liked going through the stack, it seemed
> hacky, but I came to love using dictionaries as they have some great built
> in features.

In that case, consider using function named arguments. You can simply
list a whole lot of args with defaults, and then provide values for
the exact ones you want:

def f(a=1, b=2, c=3, d=4, e=5):
    print("My args are",a,b,c,d,e)

f() # all defaults, like an empty dict
f(d=123) # all defaults but one
f(10,20,e=7) # specify the early ones positionally if you always pass those

This is a really REALLY handy feature.

ChrisA



More information about the Python-list mailing list