c[:]()

Jerry Hill malaclypse2 at gmail.com
Thu May 31 18:18:11 EDT 2007


On 5/31/07, Warren Stringer <warren at muse.com> wrote:
> In summation:
>         I started this thread asking why c[:]() wouldn't work

Because it's not part of the language.   Did you read something that
made you think it would work?  Or are you proposing a change to the
language?  I think you're better off providing the functionality
yourself, for your own containers.  Luckily, it's pretty easy to do.
Mikael Olofsson showed you how to create a custom list that, when
called, will call each of the items it contains.  Then you can use the
exact code you wrote in your first post, and it will do what you want.

>         I did not hijack another thread

You really did.  In the first message you sent, we see the following header:

> In-Reply-To: <1180504773.374529.161740 at q66g2000hsg.googlegroups.com>

What you probably did was click 'Reply' on a message in an existing
thread, then change the Subject line and delete the quoted message.
That doesn't start a new thread.  That creates a new post in the old
thread, with a new subject line and a completely unrelated message to
the rest of the thread.  If you're using a reader that groups
everything by Subject line, it may even look like you started a new
thread, but anyone who relies on the rest of the headers to build
threads correctly will see differently.

>         I posted working examples (with one typo, not quoted here)

I retyped the code you posted in the first post, and did not get the
same results as you.  Specifically:
>>> def a: print 'a'
SyntaxError: invalid syntax
>>> def b: print 'b'
SyntaxError: invalid syntax

those obviously were not copied from working code.

>>> c[:]()
TypeError: 'tuple' object is not callable

this has the correct spelling of 'tuple' in it.  Your post misspelled it.

and finally,
>>> c[0]()
a
>>> c[:][0]
<function a at 0x00CBB130>

I don't know how you could have gotten c[:][0] to print 'a', but it
wasn't by running all of the code you presented to us.

-- 
Jerry



More information about the Python-list mailing list