dpapathanasiou wrote:
> Passing the entire dictionary to every function that accesses it is
> better?
If there are a large number of functions, you could combine them and
the history_db dict into a single object.
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 14 Jan 2009 15:27:01 -0800, dpapathanasiou wrote:
>> a) a global should and need not be used.
>
> Passing the entire dictionary to every function that accesses it is
> better?
Yes. There is very little overhead when passing objects to functions in
Python. There's no performance penalty
On Thu, Jan 15, 2009 at 9:27 AM, dpapathanasiou
wrote:
> Without the "if priors:" line just above the first return statement (a
> typo perhaps?), then yes, it would do what I want.
Yes sorry it was :)
>> a) a global should and need not be used.
>
> Passing the entire dictionary to every function
> How about this then:
>
> def get_prior_versions (item_id, priors=None):
>"""Return a list of all prior item ids starting with this one"""
>global history_db # key = item id, value = prior item id
>prior_id = history_db[item_id]
>if not prior_id:
>if priors:
>retur
> You'll continue to be confused if you use that term. Python already
> has a specific use of the term “immutable”, and it doesn't apply
> here.
I was just following the terminology used in "A Byte of
Python" (which, that particular point aside, is a very good tutorial).
> Better to say: default
On Thu, Jan 15, 2009 at 8:32 AM, dpapathanasiou
wrote:
(...)
> It's not exactly right for what I'm doing, b/c the caller always
> expects a list in return.
How about this then:
def get_prior_versions (item_id, priors=None):
"""Return a list of all prior item ids starting with this one"""
dpapathanasiou writes:
> But every subsequent call returned the results of the prior call,
> plus the results of the current call.
>
> I was confused until I read in the docs that default arguments are
> immutable.
You'll continue to be confused if you use that term. Python already
has a specif
> How about:
>
> def get_prior_versions (item_id, priors=None):
>"""Return a list of all prior item ids starting with this one"""
>global history_db # key = item id, value = prior item id
>prior_id = history_db[item_id]
>if not prior_id:
>return priors
>else:
>i
> The usual solution is:
>
> def get_prior_versions (item_id, priors=None):
> if priors is None:
> priors = []
Thanks!
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, Jan 15, 2009 at 8:11 AM, dpapathanasiou
wrote:
> I wrote this function to retrieve a list of items from a dictionary.
>
> The first time it was called, it worked properly.
>
> But every subsequent call returned the results of the prior call, plus
> the results of the current call.
>
> I wa
dpapathanasiou wrote:
I wrote this function to retrieve a list of items from a dictionary.
The first time it was called, it worked properly.
But every subsequent call returned the results of the prior call, plus
the results of the current call.
I was confused until I read in the docs that defa
11 matches
Mail list logo