
On Fri, 14 Aug 2009 04:22:07 pm Prozacgod wrote:
A while back i had learned about the 'with' statement and at first I naively thought that it worked similarly to a with statement I was familiar with, from delphi/pascal - obviously it doesn't and I was instantly hit with the idea of how useful it would be to have a keyword that could use a namespace from an object, hitting the familiar __getattr__ functions and related.
What is the motivation? Is it just to reduce typing? Being an ex-Pascal coder myself, I originally missed having a Pascal-like 'with' statement too. But now I'm not so sure it is needed. I know this proposal (under the name 'with') has been discussed before, but I can't find a PEP for it... ah, here you go, it was in the FAQs: http://www.python.org/doc/faq/general/#why-doesn-t-python-have-a-with-statem... C-# doesn't have one either: http://msdn.microsoft.com/en-us/vcsharp/aa336816.aspx I don't think there are any problems with a Pascal-style 'with' statement that couldn't be overcome, but I don't think the benefit is great enough to create a new keyword for it. Can you explain in more detail why this proposed feature is useful? -- Steven D'Aprano