From: superpollo on
Stefan Behnel ha scritto:
> superpollo, 04.05.2010 13:56:
>> Stefan Behnel ha scritto:
>>> The question is: why do you have to generate the above code in the
>>> first place? Isn't a function enough that does the above?
>>
>> of course! *but* if i must generate on-the-fly python code that defines
>> a function [...]
>
> Well, could you provide a use case where you have to generate Python
> code, and where normally written code with some kind of parametrisation
> won't work?

i see your point, and mr mills gave me hints as to how to attack some of
my problems in such a fashion.

> The only thing that currently comes to my mind is a template compiler
> that translates a user provided template into an executable Python
> program. But that should be pretty trivial to do as well. I just
> remembered this little thing on Fredrik's effbot site, which should help
> here:
>
> http://effbot.org/zone/python-code-generator.htm

very good. i will most certainly give it a try.

but i do not think i can use it myself, since my template system wants
the input to generate the code to stay on a single line ( don't ask :-( )

bye
From: Stefan Behnel on
superpollo, 04.05.2010 14:46:
> my template system wants
> the input to generate the code to stay on a single line ( don't ask :-( )

I hope you don't mind if I still ask. What are you generating and for what
templating system?

Stefan

From: superpollo on
Stefan Behnel ha scritto:
> superpollo, 04.05.2010 14:46:
>> my template system wants
>> the input to generate the code to stay on a single line ( don't ask :-( )
>
> I hope you don't mind if I still ask. What are you generating and for
> what templating system?

ok, since you asked for it, prepare yourself for a bit of a horror story ;-)

i will answer in my next post

bye
From: alex23 on
Ed Keith <e_...(a)yahoo.com> wrote:
> For more information on Literate Programming in general see the following links.

None of which address the question of what you found problematic about
generating Python code. Was it issues with indentation?


From: James Mills on
On Wed, May 5, 2010 at 12:21 AM, Ed Keith <e_d_k(a)yahoo.com> wrote:
> To deal with indentation I had to
>
>   1) keep track of indentation of all chunks of code embedded in the
>      document and indent inserted chunks to the sum of all the
>      indentation of the enclosing chunks.

In my experience of non-indentation sensitive languages
such as C-class (curly braces) it's just as hard to keep track
of opening and closing braces.

--James