0
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?

1
  • 2
    What exactly are you trying to do? Commented Dec 5, 2016 at 21:06

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

You won't be able to call it like a method, though. Or rather, the 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.
As provided, the function doesn't use self.
self (the object of a method call) is always passed to a method as the first parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.