[Tutor] Python vs. PHP
alan.gauld@bt.com
alan.gauld@bt.com
Sun, 27 Jan 2002 19:45:42 -0000
> flexible, as you can write your entire page in HTML and add the PHP
> where it's needed, or you can write your entire page in PHP
> and include HTML where needed (or print it where needed).
Python (or indeed Perl) can do this too usong CGI techniques:
print '''<HTML><HEAD><TITLE>The title here</TITLE></HEAD>
<BODY>
<!-- Whatever you want here -->
</BODY></HTML>'''
So apart from adding a print statement and triple quotes
it works pretty well. To add code just break the quoted
sequence in two like so:
print '''<HTML><HEAD><TITLE>The title here</TITLE></HEAD>
<BODY>
<!-- Whatever you want here -->
''' # break the html text here
def foo():
print str(5*5) # prints 5 into the HTML
print ''' # continues the HTML text
<!-- ret of html here -->
</BODY></HTML>'''
So you can insert code into the HTML almost like you
do in PHP or ASP.
If course you can use PSP too which works exactly
like ASP/PHP but using:
[%
# Python code here
print "foobar"
%]
And On IIS you can even use ASP:
<% SCRIPT LANGUAGE='Python'>
<% print 'foobar' %>
Or whatever - I'm in an airport lounge without
access to my ASP books!
The point is that despite the hysteria generated, there
is very little to choose between ASP or CGI style web
scripting.
Alan G