Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70698

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

References <ljmaiq$3f8$1@ger.gmane.org> <5f1efb2f-9b35-44bb-b9fc-ae03777a595a@me.com>
Date 2014-04-29 08:41 +1000
Subject Re: Help with changes in traceback stack from Python 2.7 to Python 3.x
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.9563.1398724892.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Apr 29, 2014 at 5:50 AM, Andrew Konstantaras <akonsta@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Help with changes in traceback stack from Python 2.7 to Python 3.x Chris Angelico <rosuav@gmail.com> - 2014-04-29 08:41 +1000

csiph-web