suggestion: swap function in Python

Bjorn Pettersen BPettersen at NAREX.com
Thu May 31 15:54:29 EDT 2001


> From: Nick Perkins [mailto:nperkins7 at home.com]
> 
> > A swap function is impossible in Python. A function cannot rebind
names in
> > the caller's namespace. This is why del is a statement and not a
function,
> > for instance.
> >
> > --
> > Remco Gerlich
> 
> Agreed.  It is impossible for a function,
> but what if it was a statement?
> 
> Given the tiny amount of bytecode, it should be very easy to 
> implement.
> 
> suggested syntax for a 'swap' statement:
> 
> a = 10
> b = 20
> swap a b

Hmmm... new syntax (including a new reserved name) for saving two Python
VM instructions in an infrequently used piece of code... If this is
_really_ a measurable bottleneck for your code, there are better ways of
solving it.

-- bjorn




More information about the Python-list mailing list