c[:]()

Warren Stringer warren at muse.com
Wed May 30 18:37:59 EDT 2007


Hey many thanks for the replies!

Ah, so is seems that c[:][:][:][:][:][:][:][:][:][:][:][0]()
also work ...

Ah well, can't have everything. Guess I was inspired by the alphabetically
adjacent message "Call for Ruby Champion". Would have been nice for it work
- a more elegant iterator would be hard to come by. A PEP, perhaps? Maybe
not; am still a bit new - am probably missing something obvious why this
isn't an easy fix. 

Pretty cool that I can override the list class.

Cheers,

\~/

> -----Original Message-----
> From: python-list-bounces+warren=muse.com at python.org [mailto:python-list-
> bounces+warren=muse.com at python.org] On Behalf Of Brian van den Broek
> Sent: Wednesday, May 30, 2007 3:00 PM
> To: python-list at python.org
> Subject: Re: c[:]()
> 
> Warren Stringer said unto the world upon 05/30/2007 05:31 PM:
> > Hmmm, this is for neither programmer nor computer; this is for a user.
> If I
> > wanted to write code for the benefit for the computer, I'd still be
> flipping
> > switches on a PDP-8. ;-)
> >
> > This is inconsistent:
> >
> > why does c[:][0]() work but c[:]() does not?
> 
> c[:][0]() says take a copy of the list c, find its first element, and
> call it. Since c is a list of functions, that calls a function.
> 
> c[:]() says take a copy of the list c and call it. Since lists are not
> callable, that doesn't work.
> 
> > Why does c[0]() has exactly the same results as c[:][0]() ?
> 
> Because c[0] is equal to c[:][0].
> 
> > Moreover, c[:][0]() implies that a slice was invoked
> 
> Yes, but the complete slice.
> 
> > So, tell me, for scheduling a lot of asynchronous events, what would be
> more
> > readable than this:
> >
> > 	bidders = [local_members] + [callin_members]
> > 	bidders[:].sign_in(roster)
> > 	...
> 
> for bidder in [local_members] + [callin_members]:
>      bidder.sign_in(roster)
> 
> Best,
> 
> Brian vdB
> 
> > \~/
> >
> >> -----Original Message-----
> >> From: python-list-bounces+warren=muse.com at python.org [mailto:python-
> list-
> >> bounces+warren=muse.com at python.org] On Behalf Of Carsten Haese
> >> Sent: Wednesday, May 30, 2007 12:55 PM
> >> To: python-list at python.org
> >> Subject: Re: c[:]()
> >>
> >> On Wed, 2007-05-30 at 11:48 -0700, Warren Stringer wrote:
> >>> I want to call every object in a tupple, like so:
> >>>
> >>> #------------------------------------------
> >>> def a: print 'a'
> >>> def b: print 'b'
> >>> c = (a,b)
> >>>
> >>>>>> c[:]()  # i wanna
> >>> [...]
> >>> Is there something obvious that I'm missing?
> >> Yes: Python is not Perl.
> >>
> >> Python is based on the principle that programmers don't write computer
> >> code for the benefit of the computer, but for the benefit of any
> >> programmer who has to read their code in the future. Terseness is not a
> >> virtue. To call every function in a tuple, do the obvious:
> >>
> >> for func in funcs: func()
> >>
> >> HTH,
> >>
> >> --
> >> Carsten Haese
> >> http://informixdb.sourceforge.net
> >>
> >>
> >> --
> >> http://mail.python.org/mailman/listinfo/python-list
> >
> >
> 
> --
> http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list