Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion The "in"-statement

Received: by 10.180.19.234 with SMTP id i10mr21878wie.2.1352153225159;
        Mon, 05 Nov 2012 14:07:05 -0800 (PST)
X-BeenThere: python-ideas@googlegroups.com
Received: by 10.180.72.168 with SMTP id e8ls9311432wiv.3.canary; Mon, 05 Nov
 2012 14:07:05 -0800 (PST)
Received: by 10.216.216.131 with SMTP id g3mr649564wep.10.1352153225015;
        Mon, 05 Nov 2012 14:07:05 -0800 (PST)
Received: by 10.216.216.131 with SMTP id g3mr649563wep.10.1352153224970;
        Mon, 05 Nov 2012 14:07:04 -0800 (PST)
Return-Path: <python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org>
Received: from mail.python.org (mail.python.org. [82.94.164.166])
        by gmr-mx.google.com with ESMTPS id m2si339528wiz.3.2012.11.05.14.07.04
        (version=TLSv1/SSLv3 cipher=OTHER);
        Mon, 05 Nov 2012 14:07:04 -0800 (PST)
Received-SPF: pass (google.com: domain of python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org designates 82.94.164.166 as permitted sender) client-ip=82.94.164.166;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org designates 82.94.164.166 as permitted sender) smtp.mail=python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org; dkim=pass header...@python.org
Received: from albatross.python.org (localhost [127.0.0.1])
	by mail.python.org (Postfix) with ESMTP id 3XwSfc53VHzR9S
	for <python-ideas-garchive-35620@googlegroups.com>; Mon,  5 Nov 2012 23:07:04 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901;
	t=1352153224; bh=wGBwsALU2P2rZQeZWEvnqFFnxC0Vj7J5N8o/9LZCq4s=;
	h=MIME-Version:In-Reply-To:References:From:Date:Message-ID:To:Cc:
	 Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:
	 List-Subscribe:Content-Type:Sender;
	b=DXHVPwIzLbUNdt8AHQ9+qup0OsVTp/E/PT3aR/s6Ptr+a1I65LbJe2kQc9Il4JVVO
	 /0zHbrvxCzu4Xlx/SLpPY8xU9eyWN9ozNpQ6bNQLhedr59TnMvfV5URfByFToFHUz6
	 r1oEUetz4Ee4oP6Sd+62nbEgiMr9oFoiQcKmAdCg=
X-Original-To: python-id...@python.org
Delivered-To: python-id...@mail.python.org
Received: from albatross.python.org (localhost [127.0.0.1])
	by mail.python.org (Postfix) with ESMTP id 3XwSdf0027zR7F
	for <python-id...@python.org>; Mon,  5 Nov 2012 23:06:13 +0100 (CET)
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03;
	'subject:Python': 0.05; 'attribute': 0.05; 'attributes': 0.07;
	'objects,': 0.07; 'see.': 0.07; '**kwargs):': 0.09; 'lambda:':
	0.09; 'def': 0.10; '"."': 0.16; '"value"': 0.16; 'enough:': 0.16;
	'identifiers': 0.16; 'subject:ideas': 0.16; 'mon,': 0.16;
	'wrote:': 0.17; 'subject:] ': 0.19; 'modifying': 0.22; "i'd":
	0.22; 'bruce': 0.23; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25;
	'header:In-Reply-To:1': 0.25; 'appear': 0.26; 'am,': 0.27;
	'message-id:@mail.gmail.com': 0.27; 'obj': 0.29; 'read,': 0.29;
	'8bit%:5': 0.29; 'skip:& 10': 0.29; 'code': 0.31; 'could': 0.32;
	'received:google.com': 0.34; 'nov': 0.35; 'skip:. 20': 0.35;
	'received:74.125': 0.36; 'does': 0.37; 'some': 0.38; 'subject:-':
	0.40; 'header:Received:5': 0.40; 'easy': 0.60; 'skip:u 10': 0.60;
	'subject:The': 0.71; 'hand': 0.82; 'thing...': 0.84
Received: from localhost (HELO mail.python.org) (127.0.0.1)
	by albatross.python.org with SMTP; 05 Nov 2012 23:06:13 +0100
Received: from mail-ee0-f46.google.com (mail-ee0-f46.google.com [74.125.83.46])
	(using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits))
	(No client certificate requested)
	by mail.python.org (Postfix) with ESMTPS
	for <python-id...@python.org>; Mon,  5 Nov 2012 23:06:13 +0100 (CET)
Received: by mail-ee0-f46.google.com with SMTP id b15so3243258eek.19
	for <python-id...@python.org>; Mon, 05 Nov 2012 14:06:13 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=mime-version:in-reply-to:references:from:date:message-id:subject:to
	:cc:content-type;
	bh=Ktb4rJn+BNyoVh1TUwn2pe7depwDdAqWcQ/yMMj9hO0=;
	b=rcbjjGN0VY6xHtEv08nWDmNzio4lt20apFIoeZE2YmcPHIuUDK3imDgg+6mfwQDZCW
	K0R4gzu/DO2kWK8ZvSh9ISzZfy4lh4wjAxn453F5wMTBBl2QcylmCgjqxFJKjm7d3msU
	ZrhV2JQs4AVpSd6SlQWY3HXFGIVPGLBtxPkJaXHiRhyH456A3FRkVa/bNsgknhp8oZZk
	uvldiBEx66Vgl+7WMdNWrYhsMZYG7UHWEqusu3RgtX0DDUi20/I/BrqH7fI2JJTIcFGn
	1i2ZsluX2VZtdBFxdrsnh1uoudY20OA3wdplbcrbLst8EGP4x1gaOb/7n5omVT4JkT9G
	IlhA==
Received: by 10.14.200.194 with SMTP id z42mr41257196een.13.1352153173697;
	Mon, 05 Nov 2012 14:06:13 -0800 (PST)
MIME-Version: 1.0
Received: by 10.223.91.130 with HTTP; Mon, 5 Nov 2012 14:05:33 -0800 (PST)
In-Reply-To: <CAGu0AntHN21qC+38zB_UGVAwns+okvskS=3PnA0Tz4C74_c...@mail.gmail.com>
References: <20121105192841.GA26572@untibox>
	<CAGu0AntHN21qC+38zB_UGVAwns+okvskS=3PnA0Tz4C74_c...@mail.gmail.com>
From: Joshua Landau <joshua.landau...@gmail.com>
Date: Mon, 5 Nov 2012 22:05:33 +0000
Message-ID: <CAN1F8qWWoi4VJUdVB_Nqhf70fJwjS6Mu_US3JZnpHEbNchv...@mail.gmail.com>
To: Bruce Leban <br...@leapyear.org>
Cc: python-ideas <python-id...@python.org>
Subject: Re: [Python-ideas] The "in"-statement
X-BeenThere: python-id...@python.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: Discussions of speculative Python language ideas
	<python-ideas.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/options/python-ideas>,
	<mailto:python-ideas-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-ideas/>
List-Post: <mailto:python-id...@python.org>
List-Help: <mailto:python-ideas-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-ideas>,
	<mailto:python-ideas-requ...@python.org?subject=subscribe>
Content-Type: multipart/mixed; boundary="===============0730654868=="
Errors-To: python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org
Sender: "Python-ideas"
	<python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org>

--===============0730654868==
Content-Type: multipart/alternative; boundary=047d7b3440c699a44f04cdc6b177

--047d7b3440c699a44f04cdc6b177
Content-Type: text/plain; charset=ISO-8859-1

On 5 November 2012 19:47, Bruce Leban <br...@leapyear.org> wrote:

> On Mon, Nov 5, 2012 at 11:28 AM, Markus Unterwaditzer <
> mar...@unterwaditzer.net> wrote:
>
>> While mocking objects, i got annoyed by the following code pattern i had
>> to
>> use when modifying multiple attributes on a single object::
>>
>>     obj.first_attr = "value"
>>     obj.second_attr = "value2"
>>
>>     some_other = "lel"
>>
>> I thought it would be neat if i could do::
>>
>>     in obj:
>>         first_attr = "value"
>>         second_attr = "value2"
>>
>>     some_other = "lel"  # indenting this would cause it to appear as an
>> attribute of obj
>>
>
> Hard to read, error-prone and ill-defined. Does it create new attributes
> or only change existing ones? What about identifiers on right hand sides?
> What would
>     third_attr = lambda: first_attr
> do?
>

My solution has always been:

.third_attr = lambda: .first_attr
.fourth_attr = not_attr

Although a single "." is hard for some [weaklings; pah!] to see.

It has exactly one use-case in my opinion:
def m(self, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u,
v, w, x, y, z):
    in self:
        .a, .b, .c, .d, .e, .f, .g, .h, .i, .j, .k, .l, .m, .n, .o, .p, .q,
.r, .s, .t, .u, .v, .w, .x, .y, .z = \
            a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u,
v, w, x, y, z

....not that having an excuse to do this is a good thing...

And this is easy enough:
>

> def multi_setattr(obj, **kwargs):
>     for k in kwargs:
>         setattr(obj, k, kwargs[k])
>
> multi_setattr(obj,
>     first_attr = "value",
>     second_attr = "value2")
>

TYVM for this, I'd never have thought of it.

--047d7b3440c699a44f04cdc6b177
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On 5 November 2012 19:47, Bruce Leban <span dir=3D"ltr">&lt;<a href=3D"mail=
to:br...@leapyear.org" target=3D"_blank">br...@leapyear.org</a>&gt;</span> =
wrote:<div class=3D"gmail_extra"><div class=3D"gmail_quote"><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;=
border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex=
">

<div class=3D"gmail_quote"><div class=3D"im">On Mon, Nov 5, 2012 at 11:28 A=
M, Markus Unterwaditzer <span dir=3D"ltr">&lt;<a href=3D"mailto:markus@unte=
rwaditzer.net" target=3D"_blank">mar...@unterwaditzer.net</a>&gt;</span> wr=
ote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex">

While mocking objects, i got annoyed by the following code pattern i had to=
<br>
use when modifying multiple attributes on a single object::<br>
<br>
=A0 =A0 obj.first_attr =3D &quot;value&quot;<br>
=A0 =A0 obj.second_attr =3D &quot;value2&quot;<br>
<br>
=A0 =A0 some_other =3D &quot;lel&quot;<br>
<br>
I thought it would be neat if i could do::<br>
<br>
=A0 =A0 in obj:<br>
=A0 =A0 =A0 =A0 first_attr =3D &quot;value&quot;<br>
=A0 =A0 =A0 =A0 second_attr =3D &quot;value2&quot;<br>
<br>
=A0 =A0 some_other =3D &quot;lel&quot; =A0# indenting this would cause it t=
o appear as an attribute of obj<br></blockquote><div><br></div></div><div>H=
ard to read, error-prone and ill-defined. Does it create new attributes or =
only change existing ones? What about identifiers on right hand sides? What=
 would</div>



<div>=A0 =A0 third_attr =3D lambda: first_attr</div><div>do?</div></div></b=
lockquote><div>=A0</div><div>My solution has always been:</div><div><br></d=
iv><div>.third_attr =3D lambda: .first_attr</div><div>.fourth_attr =3D not_=
attr</div>

<div><br></div><div>Although a single &quot;.&quot; is hard for some [weakl=
ings; pah!] to see.</div><div><br></div><div>It has exactly one use-case in=
 my opinion:</div><div>def m(self, a, b, c, d, e, f, g, h, i, j, k, l, m, n=
, o, p, q, r, s, t, u, v, w, x, y, z):</div>

<div>=A0 =A0 in self:</div><div>=A0 =A0 =A0 =A0 .a, .b, .c, .d, .e, .f, .g,=
 .h, .i, .j, .k, .l, .m, .n, .o, .p, .q, .r, .s, .t, .u, .v, .w, .x, .y, .z=
 =3D \</div><div>=A0 =A0 =A0 =A0 =A0 =A0 a, b, c, d, e, f, g, h, i, j, k, l=
, m, n, o, p, q, r, s, t, u, v, w, x, y, z</div>

<div><br></div><div>....not that having an excuse to do this is a good thin=
g...</div><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:=
0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);=
border-left-style:solid;padding-left:1ex">

<div class=3D"gmail_quote"><div>And this is easy enough:</div></div></block=
quote><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;b=
order-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:s=
olid;padding-left:1ex">

<div class=3D"gmail_quote"><div><br></div><div>def multi_setattr(obj, **kwa=
rgs):</div><div>=A0 =A0 for k in kwargs:</div><div>=A0 =A0 =A0 =A0 setattr(=
obj, k, kwargs[k])=A0</div>

<div><br></div><div>multi_setattr(obj,</div><div>=A0 =A0 first_attr =3D &qu=
ot;value&quot;,</div><div>=A0 =A0 second_attr =3D &quot;value2&quot;)</div>=
</div></blockquote><div><br></div><div>TYVM for this, I&#39;d never have th=
ought of it.=A0</div>

</div></div>

--047d7b3440c699a44f04cdc6b177--

--===============0730654868==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas

--===============0730654868==--