I'm coming from Tcl-world ...

Martin v. Löwis loewis at informatik.hu-berlin.de
Fri Aug 2 16:49:10 CEST 2002

Andreas.Leitgeb at siemens.at (Andreas Leitgeb) writes:

> 1.) A 'for'-loop like in Tcl or in C, where you have separate
>    Init-, condition and increment-blocks, that control the loop.
>    (Of course, there's while, which can emulate all, but with that,
>    getting "continue" straight (that is: jump to the "increment-part" 
>    of the body) is probably some hassle ...)

I think you'll find that you rarely need those, since you usually
iterate over some sequence. In those cases where you do need this
construct - yes, a while loop is the idiom you'll use.

> 2.) A 'switch'-thing: like a big if-elif-elif-elif-...-else but
> which evaluates its expression only once ... and then does all the
> comparisons.

PEP 275 proposes to include such a thing. You are encouraged to
comment on the PEP, either in this group, or by contacting the PEP


> 3.) event-based scripting. (like 'fileevent','after',... in Tcl)
>    I've read somewhere, that with tkinter I get access to tcl's event-stuff,
>    But I was more after something that also works without Gui and without
>    actually using Tcl through Python.  Is there a builtin module that
>    wraps the select() or poll() systemcall, and invokes the registered
>    functions if "their" respective channel becomes readable/writable
>    or a timer runs out ?

I think the asyncore module is closest to that - although it is really
common to use select/poll explicitly, or to use threads.

> 4.) "calls by reference": maybe I'm totally misunderstanding pythons
>    function-call-concepts. I want to pass a non-global variable to
>    a subroutine, have it changed there, and find that variable
>    changed in the calling context:
>    of course doesn't work out the way I'm looking for. So what's the 
>    easiest, and (if different) what's the python'iest way to do it ?

The common approach is to mutate mutable objects. E.g.

class Counter:

def count(o):
  o.value += 1

p = Counter()
p.value = 0
print p.value

Of course, for this application, you use proper methods:

class Counter:
  def __init__(self):
    self.value = 0
  def count(self):
    self.value += 1

p = Counter()

>  Is this a bug in old versions, or has something severely changed from
>  2.0 to 2.2 that affects performance so much ?  Or is this just one of 
>  many reasons to upgrade to 2.2.1 on all the machines ?-)

I think this might be an improvement in the list.append
implementation: the map() call will add elements one-by-one, which
used to be quadratic, but isn't anymore.


More information about the Python-list mailing list