c[:]()

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Jun 1 06:57:28 EDT 2007


In <mailman.8525.1180689629.32031.python-list at python.org>, Warren Stringer
wrote:

> I like your use case. Am I correct in assuming that `y = x[:]; y()` is NOT
> to be found in working code? If that is the case, then nothing gets broken.
> It would be instructive to have a use case where enabling c[:]() would break
> existing code. 

What does "enabling c[:]()" mean?  Do you expect after "enabling it"
``c()`` and ``c[:]()`` to be different for the same list or tuple `c`?

> My use case is this:
> 
> 	do(orchestra(score)).pickle()
> 	do(orchestra(conductor)).sequence()

This isn't a use case unless you also say what the involved objects are
and what semantic you expect from this source snippet.  Just guessing,
but might the following do what you want without the need to make lists
and tuples callable?

def do(iterable, func):
    for item in iterable:
        func(item)

do(orchestra(score), pickle)
do(orchestra(conductor), sequence)

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list