print the code which defined a lambda function

<>

This question already has an answer here:

Answers


As long as you save your code to a source file you can retrieve the source code of an object using the inspect module.

example: open editor type:

myfunction = lambda x: x==2

save as lamtest.py

open shell type python to get to interactive python type the following:

>>>from lamtest import myfunc
>>>import inspect
>>>inspect.getsource(myfunc)

the result:

'myfunc = lambda x: x==2\n'

Need Your Help

How can I INSERT into a MySQL table in Python with a variable number of columns?

python mysql

I have a variable row_data = (searchindex, asin, title, browsenode, salesrank, brand, listprice, saleprice) and either of those elements might be NULL, to insert into a database, I'm using

NSDateFormatter and NSString to NSDate conversion

objective-c ios5 nsstring nsdate nsdateformatter

Good day, I'm trying to convert NSString that I'm getting from the server to NSDate object.