[Python-checkins] r67593 - python/branches/py3k/Doc/howto/webservers.rst

georg.brandl python-checkins at python.org
Fri Dec 5 19:04:41 CET 2008


Author: georg.brandl
Date: Fri Dec 5 19:04:41 2008
New Revision: 67593
Log:
#4550: fix 2.x syntax in webservers howto.
Modified:
 python/branches/py3k/Doc/howto/webservers.rst
Modified: python/branches/py3k/Doc/howto/webservers.rst
==============================================================================
--- python/branches/py3k/Doc/howto/webservers.rst	(original)
+++ python/branches/py3k/Doc/howto/webservers.rst	Fri Dec 5 19:04:41 2008
@@ -101,10 +101,10 @@
 # enable debugging
 import cgitb; cgitb.enable()
 
- print "Content-Type: text/plain;charset=utf-8"
- print
+ print("Content-Type: text/plain;charset=utf-8")
+ print()
 
- print "Hello World!"
+ print("Hello World!")
 
 You need to write this code into a file with a ``.py`` or ``.cgi`` extension,
 this depends on your web server configuration. Depending on your web server
@@ -278,8 +278,8 @@
 #!/usr/bin/env python
 # -*- coding: UTF-8 -*-
 
- from cgi import escape
 import sys, os
+ from cgi import escape
 from flup.server.fcgi import WSGIServer
 
 def app(environ, start_response):
@@ -288,7 +288,8 @@
 yield '<h1>FastCGI Environment</h1>'
 yield '<table>'
 for k, v in sorted(environ.items()):
- yield '<tr><th>%s</th><td>%s</td></tr>' % (escape(k), escape(v))
+ yield '<tr><th>{0}</th><td>{1}</td></tr>'.format(
+ escape(k), escape(v))
 yield '</table>'
 
 WSGIServer(app).run()
@@ -476,8 +477,8 @@
 Python already includes such simple templates::
 
 # a simple template
- template = "<html><body><h1>Hello %s!</h1></body></html>"
- print template % "Reader"
+ template = "<html><body><h1>Hello {who}!</h1></body></html>"
+ print(template.format(who="Reader"))
 
 The Python standard library also includes some more advanced templates usable
 through :class:`string.Template`, but in HTML templates it is needed to use


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /