On 9 dic, 02:22, "Niels L Ellegaard" <[EMAIL PROTECTED]> wrote:
> Is there a module that allows me to find errors that occur due to copy > by reference? What do you mean by "copy by reference"? > I am looking for something like the following: > > >>> import mydebug > >>> mydebug.checkcopybyreference = True > >>> a=2 > >>> b=[a] > >>> a=4 > Traceback (most recent call last): > File "<stdin>", line 1, in ? > CopyByReferenceError: Variable b refers to variable a, so please do not > change variable a. (I won't be pedantic to say that Python has no "variables"). What's wrong with that code? You are *not* changing "variable a", you are binding the integer 4 to the name "a". That name used previously to be bound to another integer, 2 - what's wrong with it? Anyway it has no effect on the list referred by the name "b", still holds b==[2] What do you want? Forbid the re-use of names? So once you say a=2, you can't modify it? That could be done, yes, a "write-once-read-many" namespace. But I don't see the usefullness. > Does such a module exist? No > Would it be possible to code such a module? I don't know what do you want to do exactly, but I feel it's not useful. > Would it be possible to add the functionality to array-copying in > numpy? No idea. > What would be the extra cost in terms of memory and CPU power? No idea yet. > I realize that this module would disable some useful features of the > language. Not only "some useful features", most programs would not even work! > On the other hand it could be helpful for new python users. I think you got in trouble with something and you're trying to avoid it again - but perhaps this is not the right way. Could you provide some example? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list