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 -

python - ValueError: could not convert string to float -

php - Laravel Get all child node count with condition -