No swap function in Python?

Aahz Maruch aahz at panix.com
Thu May 31 01:09:03 EDT 2001


In article <3B150A65.5D4986FC at europem01.nt.com>,
Bolton, Gawain [ADC:4808:EXCH] <boltong at europem01.nt.com> wrote:
>
>Unfortunately writing a generic swap function swap(a,b) with no return
>type in Python doesn't work with immutable arguments (like strings) of
>course.  Which made me think that a swap could be done like this:
>
>(a,b) = (b,a)
>
>But I'm not completely convinced doing this is safe.  

It is safe, with one caveat: it *looks* thread-safe, but it may not be.
However, if you're not writing threaded applications, you don't have to
worry about that in the slightest.
-- 
                      --- Aahz  <*>  (Copyright 2001 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het Pythonista   http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"Characters exist to suffer, you know.  An author needs a little sadism
in her makeup."  --Brenda Clough



More information about the Python-list mailing list