I'm coming from Tcl-world ...

Hans Nowak wurmy at earthlink.net
Mon Aug 5 23:26:42 EDT 2002


Andreas Leitgeb wrote:

> Whenever I start to peek into a new language, I try to recognize
> some  abstract elements in it. 
>  one of these "abstract elements" is described as such:
>    'A loop, whose body can directly and freely modify the 
>       loop-var, thereby controlling the loop'
>    (one might for example want to step back one iteration eventually, 
>     which seems unachievable with iterator-based loops)
>    ('freely' means more than continue&break)
>  In C/C++/Java/perl/Tcl there is the for-loop that fulfills it.
>  Python lacks it.

Such a loop seems a bit "un-Pythonic", but you can always emulate it with a 
while construct, I guess. I don't recall needing such a thing, but YMMV, of course.

>>Why not: [ replace continue with an if and make everything after
>>   the continue  part of the if-block]
> 
> I wrote: the location of continue may be nested arbitrarily deep down
>   inside other if's.

I may be misunderstanding something here, but my code did not contain a continue...

>>I don't know which book you used to learn Python, but it seems it taught you
>>the right things and common "Pythonic" idioms.  
> 
> It is the german translation of: 
>   "Python Pocket Reference (2nd edition)"  ("Python kurz&gut")

Ah, by Mark Lutz. I haven't read it, but I've seen favorable reviews.

>>you may find yourself using the other constructs anyway, because they "feel 
>>better".  Just give them a try.
> 
> Yes, of course.
> My intended question was not, how to program C/Tcl in python, but what 
> are Python's idioms for the mentioned "tasks".

I think the book pretty much covered them, but it's normal that they feel 
"strange" or "lacking" when you are used to a different language.

Met vriendelijke groeten,

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/




More information about the Python-list mailing list