"len()" gives a curious error

Thomas Wouters thomas at xs4all.net
Wed Mar 5 22:17:35 CET 2003

On Wed, Mar 05, 2003 at 02:19:44PM -0700, Jason Harper wrote:
> Mike McKernan wrote:
> > addr, len = string.split(args[0],"/")

> > print len(addr)

> You overwrote the 'len' builtin function with the results of a previous
> split.

The more common term is 'shadowed', Not 'overwrote'. Overwriting implies the
new 'len' comes in place of the old 'len'. This isn't the case. Just for
this one scope (function or module level), 'len' points to the string. Other
modules see the right 'len', and if the assignment was inside a function,
all other functions in the module and the module itself will see the proper
'len'. And if the assignment to len was done at the module level, a
'del len' would remove the shadowing 'len' and give you back the builtin

Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!

More information about the Python-list mailing list