Differences creating tuples and collections.namedtuples

John Reid johnbaronreid at gmail.com
Mon Feb 18 08:49:12 EST 2013


On 18/02/13 12:05, Oscar Benjamin wrote:
> On 18 February 2013 12:03, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
>> On 18 February 2013 11:47, John Reid <johnbaronreid at gmail.com> wrote:
>>> I'm seeing this problem because of the following code in IPython:
>>>
>>> def canSequence(obj):
>>>     if isinstance(obj, (list, tuple)):
>>>         t = type(obj)
>>>         return t([can(i) for i in obj])
>>>     else:
>>>         return obj
>> What is the point of the code above? If obj is a list or a tuple you
>> create a new list or tuple with the same data and then return it
>> otherwise you just return the object. What about:
> Sorry, I didn't read this properly. I see that you want apply can() to
> all the elements. What is the reason for wanting to preserve the type
> of the sequence?
>
>
Well like I said it is not me that wants to do this. It is part of the
code in IPython for sending messages between clients and engines.




More information about the Python-list mailing list