Cherry Py - 在 Python 中以 XML 形式返回输出
我的目的是在 Google App Engine 中部署网络服务。我使用 CherryPy,因为我发现它很容易理解。
import sys
sys.path.insert(0,'cherrypy.zip')
import cherrypy
from cherrypy import expose
class Converter:
@expose
def index(self):
return "Hello World!"
@expose
def fahr_to_celc(self, degrees):
temp = (float(degrees) - 32) * 5 / 9
return "%.01f" % temp
@expose
def celc_to_fahr(self, degrees):
temp = float(degrees) * 9 / 5 + 32
return "%.01f" % temp
cherrypy.quickstart(Converter())
我想知道如何以 XML 格式返回输出,就像
<?xml version="1.0" encoding="UTF-8"?>
<root>
<answer>Hello World!</answer>
</root>
我是 Python 初学者一样。请帮助我。
哈里哈兰
My intention is to deploy a web service in Google App Engine. I am using CherryPy as I found it very easy to understand.
import sys
sys.path.insert(0,'cherrypy.zip')
import cherrypy
from cherrypy import expose
class Converter:
@expose
def index(self):
return "Hello World!"
@expose
def fahr_to_celc(self, degrees):
temp = (float(degrees) - 32) * 5 / 9
return "%.01f" % temp
@expose
def celc_to_fahr(self, degrees):
temp = float(degrees) * 9 / 5 + 32
return "%.01f" % temp
cherrypy.quickstart(Converter())
I would like to know, how to return the output in XML format, like
<?xml version="1.0" encoding="UTF-8"?>
<root>
<answer>Hello World!</answer>
</root>
I am a beginner in Python. Kindly help me.
Hariharan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有类似的问题。我的解决方案是使用 xml elementtree。就像
然后从你的函数中调用 build_xml_tree
I had a similar issue. My solution was to use xml elementtree. It was something like
Then call build_xml_tree from your function