I'm coming from Tcl-world ...

Andreas Leitgeb Andreas.Leitgeb at siemens.at
Tue Aug 6 13:01:48 EDT 2002


Christos  TZOTZIOY  Georgiou <DLNXPEGFQVEB at spammotel.com> wrote:
> [example snipped, because it turned out too trivial to convey the point]

new example:
   for (<init>; <cond-a>; <incr>) {
       if (<cond-b>) {
          try { // is C++, but doesn't matter
             <code-a>
             if (<cond-c>) continue;
             <code-b>
          } catch(...) {
             <code-c>
          }
          <code-d>
       } else {
          <code-e>
       }
   }
Python: ?
  With some effort, one can surely craft equivalent code in Python,
  but I bet it will become considerably longer, and likely you'll 
  have to repeat some of the code-blocks, or introduce new flag-variables.
point taken ?


> Now, a switch statement can also be simulated, just by associating 
> a variable with the switch condition  ...
Yes, it occurred to me already:
   case=lambda x: my_special_compare(switchvar,x)
   if case('blah'): ...
   elif case(42): ...
   elif case("foo") or case("bar"):
     print "sufficiently near to a fallthrough :-)"
   elif case(r"^(.*)foo(.*?)$"): ...
   ...

switch is indeed not needed in python.

-- 
Newsflash: Sproingy made it to the ground !
  read more ... <http://avl.enemy.org/sproingy/>



More information about the Python-list mailing list