VB/Pascal with statement [was Re: Proposal for new minor syntax]

Chris Angelico rosuav at gmail.com
Sat Mar 28 02:40:01 EDT 2015


On Sat, Mar 28, 2015 at 5:26 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Sat, 28 Mar 2015 03:18 pm, Rustom Mody wrote:
>
>> One thing that is a bit laborious in python are object initializers:
>>
>> self.attr1 = field1
>> self.attr2 = field2
>>
>> In VB one can do:
>>
>> with self
>> .attr1 = field1
>> .attr2 = field2
>>
>> (or something like that -- dont exactly remember the syntax)
>
>
> Pascal is another language with a construct like that, and there's a FAQ for
> it:
>
> https://docs.python.org/2/faq/design.html#why-doesn-t-python-have-a-with-statement-for-attribute-assignments

While I don't advocate the proposal, it does have an important
difference from the one cited in the FAQ - albeit a Tim-grit
difference: the Pascal version has implicit attribute notation, where
the proposed has a leading dot. This eliminates the ambiguity, though
without majorly improving readability.

ChrisA



More information about the Python-list mailing list