Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23305

How to check if an object is created with `with` statement?

$
0
0

I would like to ensure that the class is only instantiated within a "with" statement.

i.e. this one is ok:

with X() as x: ...

and this is not:

x = X()

How can I ensure such functionality?


Viewing all articles
Browse latest Browse all 23305

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>