Add function to __builtin__ module through C API - Python source
References:
https://code.activestate.com/recipes/579110-add-function-to-__builtin__-module-through-c-api/
https://code.activestate.com/recipes/579111-add-function-to-__builtin__-module-through-c-api-c/
Save this source as you want in same directory, where C source and compiled binary exists.
After the "make", you can use it: $ ./pytestbin this_source
without ".py" extension.
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/usr/bin/python
# -*- coding: utf8 -*-
# import mymodule
# ^^^^^^^^^^^^^^^ <- no need to import module
#
# for more info, please see the references - this is just an ugly demo
def bar(d):
usleep(500000) # there isn't function by this name in std Python
print d
print type(d)
return int(d['a'] + d['b'])
|