i need provide xml file command line argument web.py app. however, library automatically takes first command line argument port number, not provide argument. there sort of trick or workaround provide xml file command line argument?
#!/usr/bin/env python import web import sys import xml.etree.elementtree et file = sys.argv[1] urls = ('/get_user/(.*)', 'get_user', '/users', 'list_users') app = web.application(urls, globals()) def read_xml(xml_file): open(xml_file, 'r') f: tree = et.parse(f) return tree.getroot() root = read_xml(file) class list_users: def get(self): output = 'users:\n' child in root: print 'child', child.tag, child.attrib output += (str(child.attrib['user']) + ': ' + str(child.attrib['name']) + ', ' + str(child.attrib['email'] + '\n')) return output class get_user: def get(self, name): child in root: if child.attrib['name'] == name: output += str(child.attrib['name']) + ", " + str(child.attrib['email']) return output output = "the user (" + name + ") couldn't found!" return output if __name__ == "__main__": app.run()
Comments
Post a Comment