[Tutor] (no subject)

Bob Gailer bgailer@alum.rpi.edu
Mon Jun 9 12:04:06 2003


At 05:09 AM 6/9/2003 +0100, Alan Gauld wrote:

> > At 06:43 PM 6/8/2003 +0200, Abel Daniel wrote:
> > >(of course this means that you have to type "Tkinter." a lot of
>places,
> >
> > <soapbox> perhaps this is a good place to mention (again) the
>desirability
> > of a "with" statement in Python.</soapbox>
>
>Bob,
>
>How would a with statement help in Python? I've seen this request
>often for C++ where it could be useful, but with Python's reference
>based naming I've never felt a need for a with in Python?
>
>I usually just use 'it' as a handy shortcut to any long chains:
>
>it = foo.bar.baz.whatever
>it.item = 42
>it.another = 27
>it.save()
>
>and so on...
>
>What exactly would a 'with' do that an 'it' doesn't?

Having programmed in Pascal, Visual FoxPro and Visual Basic (all of which 
provide "with") I am accustomed to using with. So for me
with foo.bar.baz.whatever:
     .item = 42
     .another = 27
     .save()
is more natural, more efficient, less error prone, more readable and more 
maintainable. And what would it cost to add this feature to Python?

One of my frustrations with proposing language enhancements are arguments 
from others that the proposal is not necessary. Well neither is the for 
statement. Everything it does can be implemented with the while statement. 
Yet someone deemed that a for statement "is more natural, more efficient 
and more readable." And the beauty if Python is its readability.

A similar argument came from the Visual FoxPro community around my proposal 
that an array could have a dimension of 0, e.g. be empty. In VFP arrays 
have at least one element, so when you need to have an empty array you have 
to add extra code to simulate this behavior. OTOH Python sequences can be 
empty.  Nice.

Bob Gailer
bgailer@alum.rpi.edu
303 442 2625