I'm coming from Tcl-world ...

holger krekel pyth at devel.trillke.net
Sat Aug 3 11:06:49 CEST 2002


Heiko Wundram wrote:
> Hi Andreas!
> 
> On Fri, 2002-08-02 at 18:48, Andreas Leitgeb wrote:
> > Here, I think, I didn't make my concern clear enough:
> >  in C/C++ (and similar in Tcl) I can do the following:
> >    for (int i=0,string s="*" ; i<42 ;  i++,s+=s) {
> >       ...
> >       if (...) continue;
> >       ...
> >    }
> 
> There is no way to do anything like that in Python, there just isn't.

Huh? Maybe you mean there isn't this exact syntax which is correct.

But it's not hard to translate the above *idea* into:

def counted_doubler(iterations, s):
    for i in xrange(iterations):
        yield i,s   # yields a tuple one by one to the for-loop
        s+=s

for i,s in counted_doubler(42,'*'):
    ...
    if ...:
        continue

Actually python kind of leads you into finding good 
explicit names for your ideas. Syntactic sugar is relatively 
minimal compared to other languages.

So my basic point is: Don't translate syntax, translate ideas!

have fun,

    holger




More information about the Python-list mailing list