Re: scared about refrences...




J. Clifford Dyer wrote:
SpreadTooThin wrote:
J. Clifford Dyer wrote:
SpreadTooThin wrote:
Steven D'Aprano wrote:
On Mon, 30 Oct 2006 13:10:47 -0800, SpreadTooThin wrote:


I seems that some of the objects in the list don't get along well with
deep copy..
See my second example post that used deepcopy... When run blows up...

When it blows up, is there a lot of shrapnel, or just smoke and fire?
Is the shrapnel mostly metal, or is it plastic and glass?

In short, if we don't know what's happening, we can't help.
* Did the program spit out a bunch of text you didn't understand?
If so, show us the text. That text may be incomprehensible at first,
but it contains crucial clues.

* Did it close your python window without a word?
Tell us.

* Did your computer freeze up?
Tell us.

If you don't tell us what went wrong *exactly*, you won't get a
satisfactory answer.


I would assume that looking at the code you should be able to tell..
Silly me.. Here.. is the log.. If I were helping.. I would have cut
and pasted the code myself and ran it.. instead of trying to interpret
this...

I know it seems unnecessary to post the traceback when I could get the
same thing by running your code on my machine, but it's actually useful,
for a couple reasons: First, when I run the code, I might not get an
error, or if I do, it might not be the same error you were getting, and
then we'd be on a wild goose chase. This could be because your python
installation is goofy, or because you copied in your code incorrectly.
*** happens, and I'd rather not even start down one of those blind
alleys. Third, it provides a useful frame for how to look at your
code. While a traceback might look like a big mess at first, it's
actually pretty easy to skim through once you get used to it, and it
tells me where to focus my attention in your code.


array('H', [1, 2, 3]) ['a', 'b', 'c']
Traceback (most recent call last):
File
"/Volumes/Data/Users/bjobrien/Applications/Komodo.app/Contents/SharedSupport/dbgp/pythonlib/dbgp/client.py",
line 1806, in runMain
self.dbg.runfile(debug_args[0], debug_args)
File
"/Volumes/Data/Users/bjobrien/Applications/Komodo.app/Contents/SharedSupport/dbgp/pythonlib/dbgp/client.py",
line 1529, in runfile
h_execfile(file, args, module=main, tracer=self)
File
"/Volumes/Data/Users/bjobrien/Applications/Komodo.app/Contents/SharedSupport/dbgp/pythonlib/dbgp/client.py",
line 590, in __init__
execfile(file, globals, locals)
File "/Volumes/Data/Users/bjobrien/Desktop/pythonDICOM/Text-1.py",
line 20, in __main__
test(t)
File "/Volumes/Data/Users/bjobrien/Desktop/pythonDICOM/Text-1.py",
line 16, in test
t = copy.deepcopy(x)
File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/copy.py",
line 174, in deepcopy
y = copier(x, memo)
File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/copy.py",
line 305, in _deepcopy_inst
state = deepcopy(state, memo)
File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/copy.py",
line 174, in deepcopy
y = copier(x, memo)
File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/copy.py",
line 268, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/copy.py",
line 185, in deepcopy
y = copier(x, memo)
TypeError: __deepcopy__() takes no arguments (1 given)



Cheers,
Cliff


Thanks, that's very helpful. Playing with your code a bit, I narrowed
the problem down to the array.array() structure. Looking at
help(array), there's a method defined called __deepcopy__, which, it
seems, takes no arguments, while deepcopy is passing it one argument.
Looks like a bug in the array module to me. Maybe others with more
experience using array will have some deeper insight.



I don't understand why python would insist that everything must be a
refrence...
It is of course helpful sometime but other times its not... and now
I'm sorta out
of luck...
I don't know how to make this structure immutable... Pickle it? Seems
very
inefficient to me...
Every time I pass a variable now I will worry that it will be changed
by the function...
I haven't worried about things like this since the very early days of
BASIC....
I don't know.. maybe I have more to learn.


Cheers,
Cliff

.


Quantcast