Nov-28-2020, 01:09 AM
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.
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.