Is it possible to have a Python class decorator with arguments?

Your arg_cache definition needs to do something like: def arg_cache(cthis, cthat, cthisandthat): def f(obj): obj. Cache_this = cthis obj. Cache_that = cthat obj.

Thisandthat = cthisandthat return obj return f @arg_cache(cache_this, cache_that, cache_this_and_that) The example assumes you just want to set some properties on the decorated class. You could of course do something else with the three parameters.

Your arg_cache definition needs to do something like: def arg_cache(cthis, cthat, cthisandthat): def f(obj): obj. Cache_this = cthis obj. Cache_that = cthat obj.

Thisandthat = cthisandthat return obj return f @arg_cache(cache_this, cache_that, cache_this_and_that) ... The example assumes you just want to set some properties on the decorated class. You could of course do something else with the three parameters.

In my opinion it would have been better to have named the argument to the nested function something more descriptive, like f(cls). A little more in the way of an explanation would have been nice, too. – martineau Nov 24 '10 at 10:12.

Write a callable that returns an appropriate decorator.

The example assumes you just want to set some properties on the decorated class. You could of course do something else with the three parameters. Write a callable that returns an appropriate decorator.

Terms of service. Not the answer you're looking for?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions