[PEAK] Immutable instanciation

Phillip J. Eby pje at telecommunity.com
Mon Oct 25 16:03:26 EDT 2004


At 08:46 PM 10/25/04 +0200, jdutreve at free.fr wrote:
>Hi all,
>
>I'm looking for a mean to instanciate Money like Money(1.56, Currency.USD)
>instead of Money(amount=1.56, currency=Currency.USD).
>
>class Money(model.Struct):
>
>     class amount(model.structField):
>         referencedType = FixedPoint
>         defaultValue = 0
>
>     class currency(model.structField):
>         referencedType = Currency
>         defaultValue = Currency.EUR

Well, the obvious way would be:

      def __init__(self,amount,currency):
          super(Money,self).__init__(amount=amount, currency=currency)

Or, you could do:

      def __init__(self,amount,currency):
          self.__class__.amount._setup(self,amount)
          self.__class__.currency._setup(self,currency)

but this gets tedious very quickly.




More information about the PEAK mailing list