How to copy a ClassObject?

Karlo Lozovina _karlo_ at _mosor.net_
Tue Mar 20 09:31:59 EDT 2007


Karlo Lozovina <_karlo_ at _mosor.net_> wrote in
news:Xns98F98FEF2B9A6mosornet at 161.53.160.64: 

> 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

Silly me, posted a question without Googling first ;>. This seems to be 
the answer to my question:

import new
class First:
    name = 'First'
tmp = new.classobj('tmp', (First,), {})

After this, tmp is a copy of First, and modifying tmp.name will not affect 
First.name.

P.S.
If my code is somehow mistaken and might not function properly in all 
cases, please correct me. 

Bye,
klm.

-- 
 _______                                        Karlo Lozovina - Mosor
|   |   |.-----.-----.     web: http://www.mosor.net || ICQ#: 10667163
|       ||  _  |  _  |             Parce mihi domine quia Dalmata sum.
|__|_|__||_____|_____|



More information about the Python-list mailing list