list in a tuple

Raymond Hettinger python at rcn.com
Mon Dec 24 21:01:53 EST 2007


On Dec 24, 8:22 am, montyphy... at gmail.com wrote:
> Recently, I got into a debate on programming.reddit.com about
> what should happen in the following case:
>
> >>> a = ([1], 2)
> >>> a[0] += [3]
>
> Currently, Python raises an error *and* changes the first element of
> the tuple. Now, this seems like something one would want to
> change - why raise an error *and* execute the thing it
> was complaining about?

Yawn.  Multiple actions have been combined into one line.  The first
succeeds and the second fails.

If you need commit-rollback behaviors, specify them explicitly in a
try/except.  My bet is that you'll figure-out that you didn't really
need that behavior to begin with.  No use cluttering and slowing the
language for something like this -- Python is not SQL.


Raymond



More information about the Python-list mailing list