PROBLEM?? deepcopy

Discussion in 'Python' started by phil, Jul 4, 2005.

  1. phil

    phil Guest

    I wrote the following to prove to myself that
    deepcopy would copy an entire dictionary
    which contains an instance of a class to
    one key of another dictionary.
    Note that after copying adict to ndict['x']
    I delete adict.
    Then ndict['x'] contains a good copy of adict.
    works great.


    class aclass:
    def __init__(s):
    s.anint = 123
    aninstance = aclass()
    adict = {}
    adict['y'] = aninstance

    ndict = {}
    ndict['x'] = copy.deepcopy(adict)
    del adict
    print ndict
    print ndict['x']['y']
    print ndict['x']['y'].anint # this line prints 123
    print

    Then in the following code when I try to deepcopy
    s.glob.objs I get following error
    Note that s.glob.objs is a dictionary and I am
    attempting to copy to a key of s.save, another dict,
    just like above.
    ??????????
    s.glob.objs may have several keys, the data for each
    will be instance of classes like line and circle.
    Those instances will have tkinter canvas objects in them.

    class Graph:
    def __init__(s):
    class DummyClass: pass
    s.glob = DummyClass()
    s.glob.objs = {}
    .. # here add some instance of objects like
    .. # circles and lines to s.glob.objs
    # instantiate dialog
    s.DI = dialog(s.glob)

    class dialog:
    def __init__(s,glob):
    s.glob = glob
    s.save = {}

    def proc(s):
    cur = someint
    s.save[cur] = copy.deepcopy(s.glob.objs)

    Exception in Tkinter callback
    Traceback (most recent call last):
    File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 1345, in __call__
    return self.func(*args)
    File "/home/phil/geo/g.py", line 303, in enter
    else:s.proc()
    File "/home/phil/geo/g.py", line 245, in proc
    s.save[cur][k] = copy.deepcopy(s.glob.objs[k][0])
    File "/usr/local/lib/python2.3/copy.py", line 179, in deepcopy
    y = copier(x, memo)
    File "/usr/local/lib/python2.3/copy.py", line 307, in _deepcopy_inst
    state = deepcopy(state, memo)
    File "/usr/local/lib/python2.3/copy.py", line 179, in deepcopy
    y = copier(x, memo)
    File "/usr/local/lib/python2.3/copy.py", line 270, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
    File "/usr/local/lib/python2.3/copy.py", line 179, in deepcopy
    y = copier(x, memo)
    File "/usr/local/lib/python2.3/copy.py", line 307, in _deepcopy_inst
    state = deepcopy(state, memo)
    File "/usr/local/lib/python2.3/copy.py", line 179, in deepcopy
    y = copier(x, memo)
    File "/usr/local/lib/python2.3/copy.py", line 270, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
    File "/usr/local/lib/python2.3/copy.py", line 206, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
    File "/usr/local/lib/python2.3/copy.py", line 338, in _reconstruct
    y = callable(*args)
    File "/usr/local/lib/python2.3/copy_reg.py", line 92, in __newobj__
    return cls.__new__(cls, *args)
    TypeError: function() takes at least 2 arguments (0 given)
    phil, Jul 4, 2005
    #1
    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. Replies:
    0
    Views:
    614
  2. Eugeni Doljenko

    Legitimacy of deepcopy

    Eugeni Doljenko, Jun 4, 2004, in forum: Python
    Replies:
    2
    Views:
    316
    David Bolen
    Jun 7, 2004
  3. Donnal Walter

    deepcopy in new-style classes

    Donnal Walter, Jun 22, 2004, in forum: Python
    Replies:
    0
    Views:
    258
    Donnal Walter
    Jun 22, 2004
  4. OKB (not okblacke)

    deepcopy raises TypeError for method/function?

    OKB (not okblacke), Sep 9, 2004, in forum: Python
    Replies:
    3
    Views:
    388
    Alex Martelli
    Sep 10, 2004
  5. Dan Perl
    Replies:
    0
    Views:
    318
    Dan Perl
    Sep 14, 2004
Loading...

Share This Page