[Python-ideas] function defaults and an empty() builtin
Terry Reedy
tjreedy at udel.edu
Sat May 21 23:57:44 CEST 2011
On 5/20/2011 3:10 PM, Bruce Leban wrote:
> It seems to me that a better way of doing this is:
>
> def func(optional_list=[])
> optional_list = freeze(optional_list)
If a function only needs a read-only sequence, it should not require or
to said to require a list. "def func(optional_seq = ()):". If it only
iterates through an input collection, it should only require an
iterable: "def func(optional_iter=()): it = iter(optional_iter)". If you
are paranoid and want the function to raise on any attempt to do much of
anything with the input, replace '()' with 'iter()'.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list