Re: list IndexError

Discussion in 'Python' started by Ishwor, Dec 23, 2004.

  1. Ishwor

    Ishwor Guest

    On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo
    <> 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
    Ishwor, Dec 23, 2004
    #1
    1. Advertising

  2. Ishwor wrote:
    > On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo
    > <> 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
    Scott David Daniels, Dec 26, 2004
    #2
    1. Advertising

  3. Scott David Daniels <> wrote:

    > Ishwor wrote:
    > > On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo
    > > <> 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
    Alex Martelli, Dec 27, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ishwor

    list IndexError

    Ishwor, Dec 22, 2004, in forum: Python
    Replies:
    6
    Views:
    405
    Steven Bethard
    Dec 23, 2004
  2. Ishwor

    Re: list IndexError

    Ishwor, Dec 22, 2004, in forum: Python
    Replies:
    4
    Views:
    292
    Steve Holden
    Dec 23, 2004
  3. Mike C. Fletcher

    Re: list IndexError

    Mike C. Fletcher, Dec 23, 2004, in forum: Python
    Replies:
    5
    Views:
    287
    Jeff Shannon
    Dec 23, 2004
  4. Replies:
    5
    Views:
    663
    Steven Bethard
    Mar 31, 2005
  5. Replies:
    36
    Views:
    1,596
    MonkeeSage
    Oct 11, 2006
Loading...

Share This Page