469,898 Members | 1,792 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

embedded function body

Hi,
I need to embed an user-supplied python function body in a C program.
That is, the user has no control over the function definition:

def afunction():
<here goes user code>

Now, the problem is that I can't just append the supplied string,
because I need to properly indent it which isn't trivial - just adding
a tab in front of every line won't do. I'm considering two approaches:
1) write an indent function which is more aware of python syntax;
2) use the python lexxer and work with parse trees.

I've done some experiments with 2). The idea was to parse the following
program:

def afunction():
pass

and the user supplied string (as a complete program) separately, then
replace the <suite> node in the function definition with one including
the statements from the user program.

I've got something that seems to work (but getting
allocation/deallocation right requires some work), but it seems to me
it's a bit awkward. Is the PyNode_* interface public and stable? Is it
ok to use it?

Any advice? Am I missing something? Should I try approach 1)?

TIA,
..TM.

Jul 19 '05 #1
0 858

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Pretty woman | last post: by
14 posts views Thread by Alex Molochnikov | last post: by
1 post views Thread by Jim Hammond | last post: by
2 posts views Thread by Owen.Leibman | last post: by
1 post views Thread by John Smith | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.