Need Preprocessor Module!

Skip Montanaro skip at mojam.com
Tue Jan 25 16:38:03 EST 2000


    Akinori> I would like to use preprocessor-like functionality in Python
    Akinori> like we use in C/C++.

The C preprocessor runs at compile-time.  When do you envision a Python
preprocessor running?  If you want compile-time-like behavior and have a
build/install process in place, why not run your Python source through an
existing preprocessor like m4 like so:

    $(INSTALLDIR)/%.py : %.py
	    rm -f $@
	    $(M4) $(M4FLAGS) $< > $@

I use the above in my installation process with no problems.  I typically
use it to include files containing constants, but there's no reason I
couldn't use it to select installation-dependent blocks of code as well.

    Akinori> For example, you can comment multiple lines just by "if 0" and
    Akinori> "endif" with no need to consider indenting.  You don't have to
    Akinori> take care of not embracing another comment section, I mean...

If you want run-time behavior, I think it's a small price to pay to use "if
0:" or similar construct accompanied with the indentation support provided
by a decent text editor like Emacs with python-mode running.

Skip Montanaro | http://www.mojam.com/
skip at mojam.com | http://www.musi-cal.com/
847-971-7098




More information about the Python-list mailing list