Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alias method and pass static argument too

Tags:

python

I was wondering if anybody had any ideas on how to easily alias a method (without creating another method) but pass a static argument too? An example (from how we would normally alias the object - but it obviously doesn't work) to demonstrate what I mean.

# Short and to the point
# Normal: alias = method
alias = method("static", arguments)
like image 407
Jordon Bedwell Avatar asked Jun 22 '26 20:06

Jordon Bedwell


1 Answers

from functools import partial
alias = partial(method, 'static')

or, slower but without imports:

alias = lambda *args, **kwargs: method('static', *args, **kwargs)

partial is for exactly this purpose; the lambda method is a little more flexible if you need to interleave predefined and changing arguments.

like image 100
agf Avatar answered Jun 24 '26 09:06

agf