• calcopiritus@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    11 hours ago

    You can do some kind of RAII in python with the with keyword. Only works for local variables though, where it’s easy to free resources manually

    • tias@discuss.tchncs.de
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      7 hours ago

      But if you ever forget the with keyword, you have a leak. With proper RAII the resource acquisition and release is a property of the object’s type and impossible to forget. RAII doesn’t just mean “resource acquisition is initialization”, it also implies “destruction is resource release”.