python: conditional context and ExitStack (intermediate) anthony explains

Поделиться
HTML-код
  • Опубликовано: 16 сен 2024
  • today I talk about `ExitStack` and a few uses of it: conditional contexts, variable contexts
    - context managers the hard way: • with + context manager...
    - context managers the easy way: • with + context manager...
    playlist: • anthony explains
    ==========
    twitch: / anthonywritescode
    dicsord: / discord
    twitter: / codewithanthony
    github: github.com/aso...
    stream github: github.com/ant...
    I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like to see please comment below!

Комментарии • 5

  • @Jakub1989YTb
    @Jakub1989YTb 3 года назад +3

    The third option is very neat. I hope I'll remember it when I'll need it.
    So far I've been "writing" to multiple outputs only when using logging with multiple handlers.

  • @VinayKeerthiKT
    @VinayKeerthiKT 3 года назад +1

    Whoa. I can use this to also open multiple files to write into. Brilliant. Thanks Anthony.

  • @sadhlife
    @sadhlife 3 года назад +3

    If i leave a file open, does it automatically get freed once my python process ends, at least on linux?

    • @anthonywritescode
      @anthonywritescode  3 года назад +1

      yes, but it might not be in the state you expect -- unflushed buffers, etc. (same on windows)