Changes between Version 2 and Version 3 of utilitiespy


Ignore:
Timestamp:
10/09/24 10:13:27 (7 weeks ago)
Author:
wouter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • utilitiespy

    v2 v3  
    1414== immutablelist
    1515This is a partial translation of the [wiki:immutablelist java immutablelist].
     16
     17== listener
     18This is a translation of the [wiki:Listener java Listener]
     19
     20== Tools
     21Tools contains a set of small tools for python.
     22=== enum
     23enum is a tool to support 'classic enums' in python. The classic way was to just put enumeration values inside a class. For example, math.pi equals the number 3.1415 etc. We refer to pi in math.pi as an **enum item** in the math class.
     24We call this the "classic" enumeration, to distinguish it from the more complex Enum type in python.
     25
     26This tool assumes that all enum items in the class are actual instances of that class. So for example, this SimpleEnum class contains enum items P and Q:
     27
     28{{{
     29class SimpleEnum:
     30 def val(self) -> str:
     31  return "$"
     32 @staticmethod
     33 def _static_init_():
     34  SimpleEnum.P = SimpleEnum()
     35  SimpleEnum.Q = SimpleEnum()
     36SimpleEnum._static_init_()
     37}}}
     38
     39the enum method enumValues(claz) returns all the enum items contained in that claz. So in the above example, {{{enumValues(SimpleEnum) -> [SimpleEnum.P, SimpleEnum.Q]}}}.
     40
     41The enum method enumToString(item) returns the string representation. So in the above example, enumToString(SimpleEnum.P) returns "P".