[Python-Dev] With statement

Jp Calderone exarkun@intarweb.us
Tue, 4 Feb 2003 23:10:41 -0500


--KsGdsel6WgEHnImy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Feb 04, 2003 at 05:07:54PM -0000, Duncan Booth wrote:
> On 4 Feb 2003 at 16:45, Moore, Paul wrote:
> > My actual preference is for a lock object with enter =3D acquire and
> > leave =3D release. Then, the idiom is
> >=20
> >     with my_lock:
> >         # protected code
> >=20
> > This requires a separate enter hook.
>=20
> As opposed to:
>=20
>     with lock(my_lock):
>         # protected code
>=20
> which wouldn't.
>=20
> I prefer the second, but I'm not entirely sure why. I think,=20
> maybe, it's because the parentheses in the second one tell me=20
> we are actually doing something, whereas the first one looks=20
> like a variable access which is the one thing that can't=20
> actually have side effects.

  Consider __nonzero__.  It is an insidious implementation that mutates the
object, but it isn't impossible.  In spite of this, I think I personally
prefer the second as well.

  Jp

--=20
        "I quite agree with you," said the Duchess; "and the moral of
that is -- Be what you would seem to be' -- or, if you'd like it put
more simply -- Never imagine yourself not to be otherwise than what it
might appear to others that what you were or might have been was not=20
otherwise than what you had been would have appeared to them to be
otherwise.'"       -- Lewis Carrol, "Alice in Wonderland"
--=20
 up 51 days, 7:50, 6 users, load average: 0.26, 0.35, 0.29

--KsGdsel6WgEHnImy
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)

iD8DBQE+QI7BedcO2BJA+4YRAorzAKDGHyRkI6MClhrnuTeY+0zVRWmAbACgmMeG
3jWp7L/f0x+A6MwFbgSm8JA=
=PHSM
-----END PGP SIGNATURE-----

--KsGdsel6WgEHnImy--