Q: How to generate code object from bytecode?
kwatch at gmail.com
kwatch at gmail.com
Tue Dec 26 15:55:48 EST 2006
Thanks Fredrik and Carsten,
I'll try marshal module.
> * Your code snippet is a statement, actually, a suite of statements. You
> need to exec it, not eval it.
> * You seem to think that eval'ing or exec'ing a code object will
> magically capture its output stream. It won't.
Oh, it's my mistake.
> What do you actually want to accomplish?
I'm now developping embedded python text converter.
ex. example.pyhtml
<h1>title</h1>
<ul>
<?py for item in items: ?>
<li>${item}</li>
<?py #end ?>
</ul>
ex. converted python code
_buf = []; _buf.append('''<h1>title</h1>
<ul>\n''');
for item in items:
_buf.append(''' <li>'''); _buf.append(escape(to_str(item)));
_buf.append('''</li>\n''');
#end
_buf.append('''</ul>\n''');
--
regards,
kwatch
More information about the Python-list
mailing list