python 2.7 - How to check if class is initialized using the with statement? -


i'm using class example answer make sure files cleaned up: https://stackoverflow.com/a/865272/651779

what when call

pacakge_object = packageresource() 

instead of

with packageresource() package_obj:     # stuff 

it gives error explaining class can used with statement. there way of knowing if class initialized with packageresource() package_obj: instead of pacakge_object = packageresource()?

set flag in __enter__ function, , if properties / methods of class called without flag set, cheating on you.


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -