I
Ivan Voras
Hi,
I'm looking for a construct that's similar to (Turbo) Pascal's "with"
statement. I read about the Python's new "with" statement, but I was
dissapointed to learn that it does something different (I still don't
see how it's better than try..except..finally, but that's not my question).
Is there something similar to what I want that's Pythonic enough?
(If you're not familiar with Pascal, here's how it works:
with some.big.structure.or.nested.objects.element do begin
member1 := something;
member2 := something;
end;
which exactly translates to this equivalent:
some.big.structure.or.nested.objects.element.member1 := something;
some.big.structure.or.nested.objects.element.member2 := something;
i.e. it's a wrist-saver. I think a similar feature exists in C99, for
structs.
I know it can be almost always done by using a temporary variable:
tmp = some.big.structure.or.nested.objects.element
tmp.member1 = something
tmp.member2 = something
but this looks ugly to me.)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFG7YzxldnAQVacBcgRAotkAKDeZ/uHf8WWpE+Lpk3ZM56Pnl892wCgvCOn
FDQ2/IgAA3duJ4R2vz3glpg=
=X0Y+
-----END PGP SIGNATURE-----
I'm looking for a construct that's similar to (Turbo) Pascal's "with"
statement. I read about the Python's new "with" statement, but I was
dissapointed to learn that it does something different (I still don't
see how it's better than try..except..finally, but that's not my question).
Is there something similar to what I want that's Pythonic enough?
(If you're not familiar with Pascal, here's how it works:
with some.big.structure.or.nested.objects.element do begin
member1 := something;
member2 := something;
end;
which exactly translates to this equivalent:
some.big.structure.or.nested.objects.element.member1 := something;
some.big.structure.or.nested.objects.element.member2 := something;
i.e. it's a wrist-saver. I think a similar feature exists in C99, for
structs.
I know it can be almost always done by using a temporary variable:
tmp = some.big.structure.or.nested.objects.element
tmp.member1 = something
tmp.member2 = something
but this looks ugly to me.)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFG7YzxldnAQVacBcgRAotkAKDeZ/uHf8WWpE+Lpk3ZM56Pnl892wCgvCOn
FDQ2/IgAA3duJ4R2vz3glpg=
=X0Y+
-----END PGP SIGNATURE-----