does Python support some kind of "casting"
Tino Lange
tl_news at nexgo.de
Fri Mar 15 05:17:13 EST 2002
Duncan Booth wrote:
Hi Duncan!
Thanks for your answer!
>> So the best solution is to transport an object like
>> return list(newlist)
>>
>> But I guess this makes a temporary copy of my MaxSizedList just for the
>> XML-RPC-transport, or? So it's horrible inefficient?
>>
> Yes, that will make a copy. But copying a list is a pretty efficient
> operation, so no, it isn't really horribly inefficient. Have you tried it
> and identified this as a bottleneck? How long are your lists anyway?
3600 Elements each.
No I didn't check if it's a bottleneck. But I immediately didn't feel good
when writing "return list(newlist)"
(the list contains a list of strings itself - so it's much stuff to copy)
> One way to do this that avoids the copying is to aggregate a list object
> into your class instead of trying to subclass the list type. Then you can
> simply return the internal list object if you want.
I think I'll do that.
Funny: This is the userlist-approach - so despite having the new 2.2
feature of subclassing it's better to use the old userlist.
> However, from your description I would be much more worried about the
> throwing away elements from the front of the list every time you append to
> the end of the list. I do hope you are batching these up into large chunks
> to be discarded, not throwing them away one or two at a time.
Of course :-)
This logic took most of the implementation time.
But I can just copy it in the userlist MaxSizedList - that's no problem.
Thanks!
Best regards
Tino
More information about the Python-list
mailing list