|
Revision 1203, 1.2 kB
(checked in by efphe, 1 year ago)
|
moving code from fenilot.org
|
| Line | |
|---|
| 1 |
class A(object): |
|---|
| 2 |
|
|---|
| 3 |
exporting_methods= ['seta','geta'] |
|---|
| 4 |
@staticmethod |
|---|
| 5 |
def _ready(): |
|---|
| 6 |
return getattr(A, '_the_instance', None) |
|---|
| 7 |
|
|---|
| 8 |
def __new__(cls, *p, **k): |
|---|
| 9 |
|
|---|
| 10 |
i= A._ready() |
|---|
| 11 |
if i is None: |
|---|
| 12 |
A._the_instance= object.__new__(A) |
|---|
| 13 |
if cls is A: |
|---|
| 14 |
return A._the_instance |
|---|
| 15 |
A.__init__(A._the_instance) |
|---|
| 16 |
i= A._the_instance |
|---|
| 17 |
|
|---|
| 18 |
o= object.__new__(cls) |
|---|
| 19 |
|
|---|
| 20 |
for attr_name in A.exporting_methods: |
|---|
| 21 |
setattr(o, attr_name, getattr(i, attr_name)) |
|---|
| 22 |
|
|---|
| 23 |
return o |
|---|
| 24 |
|
|---|
| 25 |
def __init__(self, a=1): |
|---|
| 26 |
self.a=a |
|---|
| 27 |
|
|---|
| 28 |
def geta(self): |
|---|
| 29 |
print self.a |
|---|
| 30 |
|
|---|
| 31 |
def seta(self, v): |
|---|
| 32 |
self.a= v |
|---|
| 33 |
|
|---|
| 34 |
def prima(self): |
|---|
| 35 |
print 'prima' |
|---|
| 36 |
self.prima= self.dopo |
|---|
| 37 |
|
|---|
| 38 |
def dopo(self): |
|---|
| 39 |
print 'dopo' |
|---|
| 40 |
|
|---|
| 41 |
class B(A): |
|---|
| 42 |
def __init__(self, x): |
|---|
| 43 |
self.x= x |
|---|
| 44 |
|
|---|
| 45 |
class C(A): |
|---|
| 46 |
def __init__(self, z): |
|---|
| 47 |
self.z= z |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
class AA: |
|---|
| 61 |
def __init__(self): |
|---|
| 62 |
pass |
|---|
| 63 |
def az(self): |
|---|
| 64 |
self.pippo=1 |
|---|
| 65 |
|
|---|
| 66 |
class BB: |
|---|
| 67 |
def __init__(self): |
|---|
| 68 |
self.medium= AA() |
|---|