return an object of a different class
aitilang
aitilang at 163.com
Tue Feb 15 21:32:57 EST 2011
More information about the Python-list mailing list
Tue Feb 15 21:32:57 EST 2011
- Previous message (by thread): return an object of a different class
- Next message (by thread): return an object of a different class
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
er................ I think you need a NumberFactory that makes SmallNumber and BigNumber according to the initial value. δΊ 2011-2-16 10:23, spam at uce.gov ει: > How can I do something like this in python: > > #!/usr/bin/python3.1 > > class MyNumbers: > def __init__(self, n): > self.original_value = n > if n <= 100: > self = SmallNumers(self) > else: > self = BigNumbers(self) > > class SmallNumbers: > def __init__(self, n): > self.size = 'small' > > class BigNumbers: > def __init__(self, n): > self.size = 'big' > > t = MyNumbers(200) > > > When I do type(t) it says MyNumbers, while I'd want it to be > BigNumbers, because BigNumbers and SmallNumbers will have different > methods etc... > > Do I need to use metaclasses? > > Thanks.
- Previous message (by thread): return an object of a different class
- Next message (by thread): return an object of a different class
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list