473,382 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

PROBLEM?? deepcopy

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)

Jul 21 '05 #1
0 1326

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Alexander Zatvornitskiy | last post by:
Hello! I have trouble with copy/deepcopy. It seems, I just don't understand something. Please explain where things goes wrong and how to do it the right way. I have one class: class...
6
by: phil | last post by:
I posted the following yesterday and got no response and did some testing simplifying the circumstances and it appears that deepcopy fails when the object to be copied contains a reference to a...
7
by: Alexandre Guimond | last post by:
Hi all, i'm trying to deepcopy a slice object but i get the following error. Does anyone know a workaround? ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on Python 2.4.3 (#69,...
4
by: Emin | last post by:
Dear experts, I got some unexpected behavior in getattr and copy.deepcopy (see transcript below). I'm not sure if this is actually a bug in copy.deepcopy or if I'm doing something too magical...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.