Zeloff
Zeloff

Reputation: 1

Lambda function in classes

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?

Upvotes: 0

Views: 88

Answers (1)

Rok Povsic
Rok Povsic

Reputation: 4935

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.

Upvotes: 2

Related Questions