Correct use of try,except and raise?
Ben Finney
bignose+hates-spam at benfinney.id.au
Sun Jul 13 09:56:40 EDT 2008
Roy Smith <roy at panix.com> writes:
> Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
>
> > If you are passing a sequence conceptually, then it's more Pythonic to
> > pass it as a sequence explicitly::
> >
> > def __init__(self, items):
> > """ Call with e.g. Stack(["foo", "bar"]) """
> > self.stack = list(items)
>
> I don't get this. You're forcing a copy to be made of the list.
The 'items' object might not be a list; it might be some other
sequence. The rest of the class (as shown by the original poster)
requires it to be a list.
> This changes the semantics of the original class, because the
> operations no longer change the original list.
Which "original class" are you referring to? The one posted by the
original poster of this thread had no "original list"; it gathered the
positional arguments (using '*items') into an 'items' parameter, which
*doesn't exist* until the function body executes.
There *is* no "original list" in that implementation posed by the
original poster; it's constructed at call time from the positional
parameters to the function.
If anything, my implementation above *preserves* that semantic, by
making a new list from the passed-in sequence.
--
\ “Consider the daffodil. And while you're doing that, I'll be |
`\ over here, looking through your stuff.” —Jack Handey |
_o__) |
Ben Finney
More information about the Python-list
mailing list