Re: copy.copy

2021-11-22 Thread ast
Le 22/11/2021 à 16:02, Jon Ribbens a écrit : On 2021-11-22, ast wrote: For immutable types, copy(foo) just returns foo. ok, thx -- https://mail.python.org/mailman/listinfo/python-list

Re: copy.copy

2021-11-22 Thread Jon Ribbens via Python-list
On 2021-11-22, ast wrote: > Hi, > > >>> a = 6 > >>> b = 6 > >>> a is b > True > > ok, we all know that Python creates a sole instance > with small integers, but: > > >>> import copy > >>> b = copy.copy(a) > &

copy.copy

2021-11-22 Thread ast
Hi, >>> a = 6 >>> b = 6 >>> a is b True ok, we all know that Python creates a sole instance with small integers, but: >>> import copy >>> b = copy.copy(a) >>> a is b True I was expecting False -- https://mail.python.org/mailman/listinfo/python-list

Re: Problem using copy.copy with my own class

2008-04-24 Thread Jeffrey Barish
warning? > One way to make this work is to define the special __copy__ method > [1], specifying explicitly how to create a copy of a Test instance: > > Normally (i.e. for pure Python classes that don't > subclass a builtin other than object) copy.copy() is smart enough to >

Re: Problem using copy.copy with my own class

2008-04-23 Thread George Sakkis
> > if __name__ == '__main__': >     t = Test(0, 0) >     t_copy = copy.copy(t) First off, inheriting from a basic builtin type such as int and changing its constructor's signature is not typical; you should rethink your design unless you know what you're doing.

Re: Problem using copy.copy with my own class

2008-04-23 Thread Gabriel Genellina
En Thu, 24 Apr 2008 01:21:15 -0300, Gabriel Genellina <[EMAIL PROTECTED]> escribió: I agree. In case arg2 were really meaningful, use __getnewargs__ (see ) I forget to include the link: -- Gabriel Genellina -- http://mail.python.org/mailman/lis

Re: Problem using copy.copy with my own class

2008-04-23 Thread Gabriel Genellina
nobody except you knows. Here it is: import copy class Test(int): def __new__(cls, arg1, arg2): ^^^ The exception is saying that copy.copy is not providing this 3rd argument. I might be a bit dense, but what would arg2 be for? Isn't arg1 supposed to

Re: Problem using copy.copy with my own class

2008-04-23 Thread Michael Torrie
ort copy > > class Test(int): > def __new__(cls, arg1, arg2): ^^^ The exception is saying that copy.copy is not providing this 3rd argument. I might be a bit dense, but what would arg2 be for? Isn't arg1 supposed to be the object instan

Re: Problem using copy.copy with my own class

2008-04-23 Thread Jeffrey Barish
rg2): return int.__new__(cls, arg1) def __init__(self, arg1, arg2): self.arg2 = arg2 if __name__ == '__main__': t = Test(0, 0) t_copy = copy.copy(t) Traceback (most recent call last): File "copytest.py", line 12, in t_copy = copy.copy(t) File &q

Re: Problem using copy.copy with my own class

2008-04-22 Thread Marc 'BlackJack' Rintsch
On Tue, 22 Apr 2008 11:13:43 -0600, Jeffrey Barish wrote: > By the way, I have simplified somewhat the code in the explanation. Please simplify the code to a minimal example that still has the problem and *show it to us*. It's hard to spot errors in code that nobody except you knows. -- http://m

Problem using copy.copy with my own class

2008-04-22 Thread Jeffrey Barish
(Pdb) myclass MyClass( 0, 0, 'A string', 123.45) (Pdb) copy.copy(myclass) *** TypeError: TypeError('__new__() takes at least 4 arguments (2 given)',) I see 4 arguments (actually, 5 because Python is passing cls invisibly to __new__). Does anyone have an idea what is going