fork(2) download
  1. from inspect import signature
  2. from functools import partial # works like a factory to create new functions.
  3.  
  4. def _inner(i): # your constant function
  5. return i
  6.  
  7. def outer(n):
  8. res = []
  9. for i in range(n):
  10. res.append(partial(_inner, i=i)) # partial fixes the current value for the function
  11. return res
  12.  
  13. for f in outer(3):
  14. print(signature(f), f())
Success #stdin #stdout 0.04s 10776KB
stdin
Standard input is empty
stdout
(*, i=0) 0
(*, i=1) 1
(*, i=2) 2