How to copy a ClassObject?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Mar 20 09:29:27 EDT 2007


In <Xns98F98FEF2B9A6mosornet at 161.53.160.64>, Karlo Lozovina wrote:

> how would one make a copy of a class object? Let's say I have:
>   class First:
>     name = 'First'
> 
> And then I write:
>   tmp = First
> 
> then 'tmp' becomes just a reference to First, so if I write 
> tmp.name = "Tmp", there goes my First.name. So, how to make 'tmp' a copy 
> of First, I tried using copy.copy and copy.deepcopy, but that doesn't 
> work.
> 
> P.S.
> Yes, I can do a:
>   class tmp(First):
>       pass
> 
> but I'd rather make a copy than a subclass.

Why?  Python isn't a prototype based programming language.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list