can regular ol' python do a php include?

John Salerno johnjsal at
Tue Oct 10 17:50:00 CEST 2006

Jean-Paul Calderone wrote:

> def include(filename):
>    print open(filename).read()
> include('header.html')
> Behold, the power of a general purpose programming language.
> Jean-Paul

Thanks, pretty good idea! But my guess is that I can't just use it this 
way within an HTML file. It seems like what I have to do is write my 
HTML files separately, with string formatters inserted in them, and then 
read *those* files into a separate Python file that is the actual URL 
visited. Not quite ideal either, but I guess that would work.

Of course, if that's how it has to be done, I might as well just use PHP 
instead. It's only one function, after all.

More information about the Python-list mailing list