homePage.py
# A function that generates Brad Pitt's home page.
# It's pretty useless. If this was what you really wanted to do, you could write the HTML directly.
def writeBradPittsHomePage():
page = """<html>
<head>
<title>Brad Pitt's Home Page</title>
</head>
<body>
<h1>Welcome to Brad Pitt's Home Page</h1>
<p>Hi! I am Brad Pitt. This is my home page!
I am interested in Angelina</p>
Here is my picture: <img src="http://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/Brad_Pitt_at_Incirlik2.jpg/200px-Brad_Pitt_at_Incirlik2.jpg">
</body>
</html>"""
outputFileName = getMediaPath("exampleHomePage.html")
outputFileObject = open(outputFileName, "wt")
outputFileObject.write(page)
outputFileObject.close()
# writeHomePage writes the home page of someone called personName who
# has a set of interests given in the text string interests and a
# portrait in the file named pictureFile into a file called
# parameterizedHomePage.html in the mediapath.
#
# This is much more useful than the previous function because you can run it repeatedly for different people
# For Brad Pitt (i.e. to generate identical HTML to the previous function), call it as follows:
# writeHomePage("Brad Pitt", "Angelina", "http://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/Brad_Pitt_at_Incirlik2.jpg/200px-Brad_Pitt_at_Incirlik2.jpg")
def writeHomePage(personName, interests, pictureFile):
# Construct the content of the home page
page = """ <html>
<head>
<title>"""
page += personName
page += """ 's Home Page</title>
</head>
<body>
<h1>Welcome to """
page += personName
page += """ 's Home Page</h1>
<p>Hi! I am """
page += personName
page += """. This is my home page!
I am interested in """
page += interests
page += """ </p>
Here is my picture: <img src='"""
page += pictureFile
page += """'>
</body>
</html>"""
# Write the content to the output file
outputFileName = getMediaPath("parameterizedHomePage.html")
outputFileObject = open(outputFileName, "wt")
outputFileObject.write(page)
outputFileObject.close()
Link to this Page