class Test:
def generate_attachment(self, type, owner_id, media_id):
return type + str(owner_id) + '_' + str(media_id)
How to represent this function like a lambda function? Do I need mark 'self' in the lambda variables?
class Test:
def generate_attachment(self, type, owner_id, media_id):
return type + str(owner_id) + '_' + str(media_id)
How to represent this function like a lambda function? Do I need mark 'self' in the lambda variables?
No, you can just do this:
my_lambda = lambda type, owner_id, media_id: type + str(owner_id) + '_' + str(media_id)
Using a parameter called type is a bad idea though since a function by that name already exists in Python and you overwrite it.
type parameter will be the instance the "method" was called on. So you'd call it like t = Test(); t.my_lambda(owner_id, media_id), and type would be the t object. Probably not what the OP wants.self.self (the object of a method call) is always passed to a method as the first parameter.