For __getattr__and __setattr__you will have to wait while someone with a deeper understanding describes the new Scala 2.10 API. (And, of course, it will not be directly translated ever. It depends entirely on your use case. If you just want a dynamic class, there will be a Dynamicsign in the future , and if you just want it a little, then designing around pattern matching may be an obvious choice.)
__*__ Python:
__call__ → apply()//__metaclass__// :class trait mixins- , , ,
super(); Scala super() .
__repr__, __str__ → toString()__eq__ → equals()__init__//__new__// ; __del__//__nonzero__// , implicit def toBool[MyType](a: MyType): Boolean = ...
__len__ ⇝ length, size -__getitem__ → apply(i: IndexType)// - Scala__setitem__ → update(i: IndexType, v: ValueType)__delitem__// ;__iter__ → foreach(block: ValueType => Unit)// : map, flatMap
, apply update Scala, Python. :
val x = collection(elem)
collection(elem) = y
, Pythons __iter__ (el for el in container) foreach map, for (el <- container) yield el.
, , :
__add__, __sub__,...// def + (arg: T) def - (arg: T)
__lt__, __ge__ → def <(other: T), def <=(other: T)
, Python, :
__radd__, __rsub__,...//- ; . def +: (arg: T) def -: (arg: T) ( :)__iadd__, __isub__,...// : def += (arg: T),...
: Scala 's magic "