python3: 'where' keyword

Carlos Ribeiro carribeiro at gmail.com
Sat Jan 8 17:17:08 EST 2005


On Sat, 08 Jan 2005 12:53:05 -0500, Peter Hansen <peter at engcorp.com> wrote:
> Andrey Tatarinov wrote:
> >  >>> print words[3], words[5] where:
> >  >>>     words = input.split()
> >
> > - defining variables in "where" block would restrict their visibility to
> > one expression
> 
> Then your example above doesn't work...  print takes a
> sequence of expressions, not a tuple as you seem to think.

I found it strange that he had chosen to make the example with
"print", that is a statement. I'm not sure how could it be made to
work with both expressions and statements, it just seems strange...

Overall, I found the idea interesting. It seems like a obvious
counterpart to "with", in the sense that both act as modifiers to the
scoping rules. I think it can be made to work, and that it would lead
to elegant & readable code, but there are still lots of things to
consider: exception handling, fast name lookup in the "where" block,
access to symbols outside the "where" block, just to name a few.

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com



More information about the Python-list mailing list