Stop python
Ken Seehof
kens at sightreader.com
Tue Apr 17 04:43:59 EDT 2001
From: "Steve Holden" <sholden at holdenweb.com> wrote:
> "Ken Seehof" <kens at sightreader.com> wrote ...
> > Hey, this reminds me of a useless python idea I had a few years ago.
> >
> > First write a streaming preprocessor for python. Make a fancy
> > importer that makes *.py dependent on *.ppy the same way *.pyc
> > is dependent on *.py. Then add a preprocessor command "exit()".
> >
> > # example.ppy
> > print 'hello',
> > #!x=5
> > #!if x==5:
> > #! print "print 'lumberjacks.'"
> > #! exit()
> > print 'world.'
> >
> > This would be a fun project that I don't have time for. Any idea why
> > it would be useful? I might be willing to coauthor it if someone else
> > wants to do the import logic (custom importers make my head hurt).
> >
> > Of course it's most likely useless since python's a bit too dynamic to
> > really -need- a proprocessor, but I could be missing something.
> >
> > In case you are confused:
> > The preprocessor copies lines that don't start with "#!".
> > The preprocessor executes lines that start with "#!".
> > The print statement (stdout) is redirected to preprocessor output.
> >
> > David V. wrote:
> > > Is it possible to stop parsing python program at some point, for
> > > example, like in shell script using 'exit'?
> >
> This was actually a useless PL/1 idea a long time before Python existed.
>
> regards
> Steve
I always though it was kind of stupid that the C/C++ preprocessor wasn't
more like a real language. I have used python as a preprocessor for C++
with interesting results. Not recommended for the general case, but there
are odd situations where you really need extra control over what code gets
generated (maybe once every 3 or 4 years).
- Ken
More information about the Python-list
mailing list