c[:]()

Steve Holden steve at holdenweb.com
Fri Jun 1 01:58:27 CEST 2007


Warren Stringer wrote:
> Quotes out of context with mistaken assumptions, now follow:
> 
>>>>>> So c[:]() -- or the more recent go(c)() -- executes all those
>>>>>> behaviors.
>> No it doesn't. See below.
>>> If c[:]() works, the so does this, using real world names
>>>
>>> 	orchestra[:].pickle()
>>> 	orchestra[conductor()].sequence()
>>>
>>> Though, I'm already starting to prefer:
>>>
>>> 	do(orchestra).pickle()
>>> 	do(orchestra(conductor)).sequence()
>>>
>> Yes, dammit, but c[:]() *DOESN'T WORK* unless you have made some pretty
>> crufty changes to the underlying object.
> 
> I started this thread asking why c[:]() doesn't work. 
> 
If you say so. Perhaps you didn't express yourself too clearly.

>> This is what I'm having difficulty understanding. You said, in your
>> original post (which, by the way, hijacked another thread about
>> something completely different):
> 
> What?!? I started this thread. 
> 
No you didn't. Your original post was a reply to a message whose subject 
line was 'Re: "is" and ==', and included the header

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

>>> I want to call every object in a tupple, like so:
>>>
>> [By the way, that's "tuple", not "tupple"]
>>> #------------------------------------------
>>> def a: print 'a'
>>> def b: print 'b'
>>> c = (a,b)
>>>
>>>>>>>>> c[:]()  # i wanna
>>>  TypeError: 'tupple' object is not callable
>>>
>>>>>>>>> c[0]()  # expected
>>> a
>>>>>>>>> c[:][0] # huh?
>>> a
> 
>> This is what I just don't believe. And, of course, the use of "tupple"
>> above tells us that this *wasn't" just copied and pasted from an
>> interactive session.
> 
> Try it.
>  
>>>>>>>>> [i() for i in c] # too long and ...huh?
>>> a
>>> b
>>> [None,None]
>>> #------------------------------------------
>> This is also clearly made up.
> 
> I repeat: try it.
> 
I don't need to. The function definitions contain syntax errors, and the 
error message couldn't have been produced by any interpreter that ever 
existed.

>> In a later email you say:
>>
>>> why does c[:][0]() work but c[:]() does not?
>> The reason for this ...
> 
> Stated elsewhere, but thanks
> 
>>> Why does c[0]() has exactly the same results as c[:][0]() ?
>> The reason for this is that c is exactly the same as c[:]. The slicing
>> notation "[:]" tells the interpreter to use a tuple consisting of
>> everything in the tuple to which it's applied. Since the interpreter
>> knows that tuples are immutable (can't be changed), it just uses the
>> same tuple -- since the immutability there's no way that a difference
>> could arise between the tuple and a copy of the tuple, Python doesn't
>> bother to make a copy.
>>
>> This behavior is *not* observed with lists, because lists are mutable.
> 
> But neither tupples or lists work, so immutability isn't an issue.
> 
Good grief, man, c[0]() will work perfectly well as long as c is a list 
or a tuple of functions. Or, come to that, a dict of functions with a 
key of 0.

>> I realise you are trying to find ways to make Python more productive for
>> you, and there's nothing wrong with that. But consider the following,
>> which IS copied and pasted:
>>
>>  >>> def a():
>> ...   print "A"
>> ...
>>  >>> def b():
>> ...   print "B"
>> ...
>>  >>> c = (a, b)
>>  >>> c
>> (<function a at 0x7ff4f764>, <function b at 0x7ff4f64c>)
>>  >>> c[:]
>> (<function a at 0x7ff4f764>, <function b at 0x7ff4f64c>)
>>  >>> c[0]()
>> A
>>  >>> c[1]()
>> B
>>  >>> c()
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>> TypeError: 'tuple' object is not callable
>>  >>> c[:]()
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>> TypeError: 'tuple' object is not callable
>>  >>>
> 
> I never said that c() would execute a list nor did I ever say that c[:]()
> would execute a list. 
> 
>> I think the fundamental mistake you have made is to convince yourself that
>>
>>      c[:]()
>>
>> is legal Python. It isn't, it never has been.
> 
> In summation: 
> 	I started this thread asking why c[:]() wouldn't work
> 	I did not hijack another thread
> 	I posted working examples (with one typo, not quoted here)
> 	I am extremely annoyed by this post
> 	
> Tis best not to assume what other people are thinking 
> 	
> 
Probably best not to try to help them too, if this is the response. Next 
time you want assistance try to ensure that you copy and paste your 
examples instead of trying to duplicate them from memory.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com        squidoo.com/pythonology
tagged items:         del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------




More information about the Python-list mailing list