Equivalent to Python with Statement
meppl
mephisto at nordhoff-online.de
Wed Feb 28 22:08:36 UTC 2018
On Wednesday, 28 February 2018 at 22:00:11 UTC, meppl wrote:
> On Wednesday, 28 February 2018 at 21:47:40 UTC, Cym13 wrote:
>> On Tuesday, 27 February 2018 at 16:17:20 UTC, Jonathan wrote:
>>> [...]
>>
>> Others have discussed that particular case at length, but to
>> provide a more generic answer the correct way to translate a
>> python context manager is to use scope(out):
>>
>> { // Scope restriction similar to with's block
>> auto f = File("x.txt");
>> scope(out) f.close(); // closes f on scope exit no
>> matter what
>>
>> /* do stuff with f */
>> }
>>
>> This accurately reproduces the behaviour of python's with
>> although it's less automatic.
>
> what is `scope(out)`? I only know these
> file:///usr/share/dmd-doc/html/d/spec/statement.html#ScopeGuardStatement
sorry, my question was not good. I thought there is an
undocumented feature, never mind ;)
More information about the Digitalmars-d-learn
mailing list