What is the equivalent of the C# “using” block in IronPython?

前端 未结 5 858
不思量自难忘°
不思量自难忘° 2020-12-06 05:09

What\'s the equivalent of this in IronPython? Is it just a try-finally block?

using (var something = new ClassThatImp         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 05:26

    There is the with statement: http://www.ironpythoninaction.com/magic-methods.html#context-managers-and-the-with-statement

    with open(filename) as handle:
        data = handle.read()
        ...
    

提交回复
热议问题