Python中文
首页
教程
问答
标签
搜索
登录
注册
有人能解释一下这个Python代码吗?(可能使用装饰器)
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我试图用Python编写一个简单(轻量级)RESTful服务器。我遇到了来自<a href="http://code.google.com/p/mimerender/" rel="nofollow">Google</a>的以下代码:</p> <pre><code>import web import json from mimerender import mimerender render_xml = lambda message: '<message>%s</message>'%message render_json = lambda **args: json.dumps(args) render_html = lambda message: '<html><body>%s</body></html>'%message render_txt = lambda message: message urls = ( '/(.*)', 'greet' ) app = web.application(urls, globals()) class greet: @mimerender( default = 'html', html = render_html, xml = render_xml, json = render_json, txt = render_txt ) def GET(self, name): if not name: name = 'world' return {'message': 'Hello, ' + name + '!'} if __name__ == "__main__": app.run() </code></pre> <p>我不熟悉<code>@mimerender</code>行中使用的语法。但是,我通常会遇到这样一个decorator和-date-decorator的组合:</p> ^{pr2}$ <p>代码的<code>@mimerender</code>部分是什么意思/do?在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>这里发生的是<code>mimerender</code>是一个要获得的装饰器:</p> <pre><code>@mimerender def GET(self, name): </code></pre> <p>但是还有一些参数需要传递给<code>mimerender</code>,所以它们就在那里完成了。在</p> <p>从<code>mimerender</code>的docstring中,如果需要额外的阅读:</p> ^{pr2}$
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
8 回答
如何在python中从数据帧列表中删除引号
4 回答
如何在python中从数据帧创建列表
5 回答
如何在Python中从数据帧创建嵌套的JSON
8 回答
如何在Python中从数据帧显示wordcloud
7 回答
如何在Python中从数据帧的时间戳中删除字符
4 回答
如何在Python中从数据帧绘制简单绘图?
5 回答
如何在python中从数据帧行提取具有特定长度的范围?
8 回答
如何在python中从数据帧设置dict中的值
7 回答
如何在Python中从数据库中获得一个结果
6 回答
如何在python中从数据框中绘制分类条形图
10 回答
如何在Python中从数据框中选择特定细节?
10 回答
如何在python中从数据集中删除unicode
1 回答
如何在python中从数据集中删除某些数值?
2 回答
如何在python中从数据集中选择行
7 回答
如何在Python中从数组中删除元素
1 回答
如何在python中从数组中删除单个倒逗号?
7 回答
如何在python中从数组中删除对象?
1 回答
如何在python中从数组中删除引号
2 回答
如何在python中从数组中删除所有最小值
1 回答