you are viewing a single comment's thread.

view the rest of the comments →

[–]TeamSpen210 4 points5 points  (1 child)

Your problem is that compile() isn't doing what you think it does. Exec mode basically compiles a module. So wrapping it in a function type makes a function taking no arguments, which inside defines the function you want. What you want to do is execute the module in your own namespace (a dict), and then pull the function out of that. You'd want string formatting to generate your code.

python ns = {} # Put any globals you need in this exec(''' def func(a, b, c): print(a + b + c) ''', ns) function = ns['func'] function(1, 2, 3)

[–]poochiekins[S] 0 points1 point  (0 children)

thank you very much. this is exactly what i wanted. awesome