⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makexml.py

📁 python web programming 部分
💻 PY
字号:
#!/usr/bin/python# Python program that outputs XMLrecipe = {    'title' : 'Famous Guacamole',    'description' : 'A southwest favorite!',    'ingredients' : [ ('4',None,'Large avocados, chopped'),                      ('1',None,'Tomato, chopped'),                      ('1/2', 'C', 'White onion, chopped'),                      ('2','tbl','Fresh squeezed lemon juice'),                      ('1',None,'Jalapeno pepper, diced'),                      ('1','tbl','Fresh cilantro, minced'),                      ('1','tbl','Garlic, minced'),                      ('3','tsp','Salt'),                      ('12','bottles','Ice-cold beer')                    ],    'directions'  : 'Combine all ingredients and hand whisk to desired '                    'consistency. Serve and enjoy with ice-cold beers'   }# Turn a recipe into XMLdef make_xml(r):    def make_item(num,units,desc):        if units:            return '<item num="%s" units="%s">%s</item>\n' % (num,units,desc)        else:            return '<item num="%s">%s</item>\n' % (num,desc)    # Make ingredient item list    ingr_str = "".join([make_item(*i) for i in r["ingredients"]])    print """<?xml version="1.0" encoding="iso-8859-1"?><recipe><title>%(title)s</title><description>%(description)s</description>""" % recipe    print """<ingredients>%s</ingredients>""" % ingr_str    print """<directions>%(directions)s</directions></recipe>""" % recipe# Try it outmake_xml(recipe)    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -