Python代码只创建三个HTML页面

时间:2015-07-05 01:39:32

标签: python html

我有:

fruits = [ apple, pineapple, banana, oranges]
sizes = [ small, medium, large] 

和每种水果大小的组合

( apple-small, apple-medium, pineapple-large etc.)

我有fruitproperties = [color, size, weight] 每种组合对颜色,大小都有不同的描述,可能有新的水果特性。

我正在尝试为此创建索引页面: 以下是我的python代码:

def home(fruit):
    htmlfile = open('home.html', 'w')
    htmlfile.write = ("<!DOCTYPE html>\n")
    htmlfile.write=("<html>\n")
    htmlfile.write=("<head>\n")
    htmfile.write = ("<title> Fruit-home page </title>\n") 
    htmlfile.write =("</head>\n")
    htmlfile.write = ("<body>\n")
    for fruit in fruits: 
        htmlfile.write=('<a href ="'+fruit+'.html"> The fruit list </a><br>\n')
    htmlfile.write = ("</body>\n")
    htmlfile.write = ("</html>\n")

现在对于fruit.html我有以下def

def fruit_pages(fruit)
    for fruit in fruits: 
        htmlfile = open(fruit+".html","w")
        htmlfile.write = ("<!DOCTYPE html>\n")
        htmlfile.write=("<html>\n")
        htmlfile.write=("<head>\n")
        htmfile.write = ("<title> Individual page</title>\n") 
        htmlfile.write =("</head>\n")
        htmlfile.write = ("<body>\n")
# Problem is with following code 
            for fruit in fruits:
                for size in sizes:
                    htmlfile.write('<a href= "'+size+'.html">'+size+'</a><br>\n')
            htmlfile.write("</body>\n")
            htmlfile.write("</html>\n")
            htmlfile.close()

上面的代码只创建三个html页面,大小为

small.html, medium.html and large.html 

并将其链接到每个fruit.html

因为每个html中的信息对于每个水果都是不同的。我想为每个水果创建3个html页面。 喜欢

apple - apple_small.html, apple_medium.html, apple_large.html 
pineapple - pineapple_small.html, pineapple_medium.html, pineapple_large.html

等等。并将其链接到相应的fruit.html页面。

#code for size.html 

def size_html(size)
    htmlfile = open(size+".html","w")
    htmlfile.write = ("<!DOCTYPE html>\n")
    htmlfile.write=("<html>\n")
    htmlfile.write=("<head>\n")
    htmfile.write = ("<title> size - fruit properties</title>\n") 
    htmlfile.write =("</head>\n")
    htmlfile.write = ("<body>\n")

    some code for linking it to individual fruitproperty.html pages         
    htmlfile.write("</body>\n")
    htmlfile.write("</html>\n")
    htmlfile.close()

我该怎么做?

0 个答案:

没有答案