Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: list IndexError

Reply
Thread Tools

Re: list IndexError

 
 
Ishwor
Guest
Posts: n/a
 
      12-23-2004
On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo
<(E-Mail Removed)> wrote:
>
>
> [Steven Bethard]
>
> #- True, true. Maybe you could lobby for copy as a builtin in
> #- Python 3000?
>
> That's a good idea to me. But copy() as a builtin is not clear if it's
> shallow or deep.


IMHO its preferable to use shallow one as the built-in because deep is
expensive op. for CPU. ~


>
> . Facundo
>
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


[snip]
--
cheers,
Ishwor Gurung
 
Reply With Quote
 
 
 
 
Scott David Daniels
Guest
Posts: n/a
 
      12-26-2004
Ishwor wrote:
> On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo
> <(E-Mail Removed)> wrote:
>>#- True, true. Maybe you could lobby for copy as a builtin in
>>#- Python 3000?
>>
>>That's a good idea to me. But copy() as a builtin is not clear if it's
>>shallow or deep.

>
> IMHO its preferable to use shallow one as the built-in because deep is
> expensive op. for CPU. ~

"deepcopy" is an operation that is less well defined than shallow copy
anyway (and hence shouldn't be a default). Objects representing
constants may contain a cache (for example) as an efficiency measure,
and "deepcopy" needn't copy such objects. The only way to safely
do deepcopy is to copy down to immutables, but usually there is a
shallower and faster implementation that depends on application
semantics.

--Scott David Daniels
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Alex Martelli
Guest
Posts: n/a
 
      12-27-2004
Scott David Daniels <(E-Mail Removed)> wrote:

> Ishwor wrote:
> > On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo
> > <(E-Mail Removed)> wrote:
> >>#- True, true. Maybe you could lobby for copy as a builtin in
> >>#- Python 3000?
> >>
> >>That's a good idea to me. But copy() as a builtin is not clear if it's
> >>shallow or deep.

> >
> > IMHO its preferable to use shallow one as the built-in because deep is
> > expensive op. for CPU. ~

> "deepcopy" is an operation that is less well defined than shallow copy
> anyway (and hence shouldn't be a default). Objects representing
> constants may contain a cache (for example) as an efficiency measure,
> and "deepcopy" needn't copy such objects. The only way to safely
> do deepcopy is to copy down to immutables, but usually there is a
> shallower and faster implementation that depends on application
> semantics.


Well, that's what methods __copy__ and __deepcopy__, or the
often-preferable __getstate__ and __setstate__, are all about -- letting
your classes explicitly define what IS the state (that needs to be
copied) of their instances. I don't see how that changes between
copy/deepcopy being built-ins or being in a standard library module like
today. Yes, deep copy is way more involved and expensive that shallow
copy, etc, etc, but, again, this holds whether they're built-ins or come
from a standard library module.

I guess I must be missing something...?


Alex
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get around "IndexError: list index out of range" erikwickstrom@gmail.com Python 36 10-11-2006 04:56 AM
returning a list: IndexError shama.bell@gmail.com Python 5 03-31-2005 05:20 PM
Re: list IndexError Mike C. Fletcher Python 5 12-23-2004 06:15 PM
list IndexError Ishwor Python 6 12-23-2004 03:57 PM
Re: list IndexError Ishwor Python 4 12-23-2004 03:16 PM



Advertisments