How can I easily find out if a Python class accepts a keyword?

The only time I've ever used a keyword withis reading and writing files, mainly because the only case that I really know can use. I can imagine that there are numerous cases where I preferred to use with, but did not know that the class or method accepted it.

So, how can I identify instances where a keyword can be used with?

+4
source share
1 answer

Context managers have methods, __enter__()and __exit__()so check if these attributes exist and that they have attributes __call__that will work almost all the time.

But yes, first read the code and / or documentation for the class.

+3
source

All Articles