I’m writing a pretty simple function for use in my Django project to display a number of pages only if the application is in debug mode. In AS3, you can essentially apply a methods parameters to another methods using that method’s call or apply method. Let me demonstrate:
public function secureCall(...arguments):void {
if (SECURE == true) {
// reference the 'call' method below
call.apply(this, arguments);
} else {
throw new IllegalAccessError();
}
}
public function call(a:String, b:int, ...others):void {
// do something important
}
Is there a way to do this in Python? I essentially want to do the following:
from django.views.generic.simple import direct_to_template
def dto_debug(...args):
if myapp.settings.DEBUG:
direct_to_tempate.apply(args)
else:
raise Http404
When defining a function, you can use this notation:
argswill be a tuple of positional arguments,kwargsa dict of keyword argumentsYou can then call another function with these arguments like this:
You can omit either of the
*argsor**kwargsif you don’t want to pass positional or keyword arguments, respectively. You can of course create the tuple/dict yourself, they don’t have to come from adefstatement.