Python Forum
getting my head arounnd __enter__() for my new class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting my head arounnd __enter__() for my new class
#1
i am creating a class to open a file via one of a few other methods/function based on the name to be opened. if the name of the file ends with '.bz2' then it will import bz2 and call bz2.open() to get an object that will compress or uncompress the file as it writes or reads it.

so i am trying to add context management for this class so it can be used on a with statement. i am working on __enter__() first. but this is confusing about what argument(s) it will get and what it should return when. the __exit__() seems simple but even it has confusion. PEP343 got into a lot of other details and i was unable to match it up to my misunderstanding of this API.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
getting my head arounnd __enter__() for my new class - by Skaperen - Nov-28-2020, 01:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  parser for LVM head Skaperen 0 1,469 Nov-02-2019, 04:04 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020