Re: Does D have any construct like Python's with keyword?

2016-08-27 Thread Daniel Kozak via Digitalmars-d-learn
Dne 27.8.2016 v 02:04 pineapple via Digitalmars-d-learn napsal(a): I would just love if I could express this as something more like context(auto file = File("some_file.txt")){ file.write(); } void main(string[] args) { with(File("some_file.txt")) { write();

Re: Does D have any construct like Python's with keyword?

2016-08-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 27 August 2016 at 00:04:47 UTC, pineapple wrote: context(auto file = File("some_file.txt")){ file.write(); } You don't need to do anything special for that in D, structs are destructed automatically. Plain auto file = File("some_file.txt"); file.write(); will

Re: Does D have any construct like Python's with keyword?

2016-08-26 Thread pineapple via Digitalmars-d-learn
I would just love if I could express this as something more like context(auto file = File("some_file.txt")){ file.write(); }

Re: Does D have any construct like Python's with keyword?

2016-08-26 Thread pineapple via Digitalmars-d-learn
On Friday, 26 August 2016 at 23:30:15 UTC, Cauterite wrote: On Friday, 26 August 2016 at 23:28:27 UTC, pineapple wrote: I've grown to very much appreciate how context initialization and teardown can be very conveniently handled using `with` in Python. Is there any clean way to imitate this

Re: Does D have any construct like Python's with keyword?

2016-08-26 Thread Cauterite via Digitalmars-d-learn
On Friday, 26 August 2016 at 23:28:27 UTC, pineapple wrote: I've grown to very much appreciate how context initialization and teardown can be very conveniently handled using `with` in Python. Is there any clean way to imitate this syntax in D? Yep, scope guards. auto p = OpenProcess(...);