TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Underscore.py / a python port of underscore.js

37 点作者 serkanyersen超过 12 年前

14 条评论

serkanyersen超过 12 年前
Hi Everyone,<p>First of all, thank you all for your comments. I have to clarify the purpose of this library. I'm originally a JavaScript developer and I didn't write a single line of python code before this project.<p>I needed a project to learn python and I choose something I'm already familiar with. Underscore.js has almost everything you want to learn on a new language and it thought me a lot.<p>When I completed the project I figured I can post it online and other clueless javascript developers like myself can learn python from a familiar place.<p>I'm fully aware that python already has most of the tools underscore has and this code is not pythonic at all. It was built that way intentionally. I wanted it to be the same as underscore.js.<p>Now I need your advice to write a better python code and maybe create a useful library after all.<p>Thank you all.<p>PS: I wrote this comment from mobile phone so please excuse any errors.
评论 #4495855 未加载
评论 #4495823 未加载
jmagnusson超过 12 年前
Why, oh why?<p>map(str.upper, ['foo', 'bar']) == _(["foo", "bar"]).invoke("upper")<p>[w for w in ["foo", "hello", "bar", "world"] if len(w) &#62; 3] == _.filter(["foo", "hello", "bar", "world"], lambda x, <i>a: len(x) &#62; 3)<p>sorted([i </i> 2 for i in [10, 48, 56, 30, 20] if i &#62; 20]) == _([10, 48, 56, 30, 20]).chain().filter(lambda x, <i>a: x &#62; 20).map(lambda x, </i>a: x * 2).sortBy().value()
评论 #4495613 未加载
评论 #4495593 未加载
michaelhoffman超过 12 年前
I hesitate to add to the negative response to what is surely a well-meaning free project for the world. But `_` is really a poor choice for a variable name in Python. It is already used as:<p>* the value of the last expression in the REPL<p>* a conventional abbreviation for `gettext.gettext` (<a href="http://docs.python.org/library/gettext.html" rel="nofollow">http://docs.python.org/library/gettext.html</a>)<p>* a conventional throwaway variable (for `str.partition` and other functions that return a larger tuple than you want)<p>And for most of these features, invoking them through a object/class method rather than a standalone function is unwieldy (and unpythonic)
评论 #4496323 未加载
评论 #4496339 未加载
djacobs超过 12 年前
It is hilarious that someone would have the knowledge to build this but not know that it was already implemented as part of the language.<p>Is this a parody?
评论 #4495798 未加载
评论 #4496935 未加载
评论 #4495762 未加载
stephen_mcd超过 12 年前
Most of the methods provided are functions already built into Python (map, filter, reduce, all, any, min, max)<p>Also the underscore variable name conflicts with the common convention of using an underscore as the i18n translation function.<p>Those issues aside, the templating looks handy, and I'm sure the whole thing was fun to write.
FuzzyDunlop超过 12 年前
<p><pre><code> VERSION = "0.1.2" """ Version of the library """ </code></pre> This is a good example of unnecessary commenting.<p>But I think this port misses the point of Underscore.js, which is to make the same functional features of the language available to all browser implementations, because not all browsers have forEach, or filter, or reduce, etc. In Python, or other languages? The features are already there.
评论 #4495890 未加载
draegtun超过 12 年前
Other Underscore.js ports (that I know of):<p>Perl - <a href="http://vti.github.com/underscore-perl/" rel="nofollow">http://vti.github.com/underscore-perl/</a><p>Lua - <a href="http://mirven.github.com/underscore.lua/" rel="nofollow">http://mirven.github.com/underscore.lua/</a><p>PHP - <a href="http://brianhaveri.github.com/Underscore.php/" rel="nofollow">http://brianhaveri.github.com/Underscore.php/</a><p>Actionscript 3 - <a href="https://github.com/amacdougall/underscore.as" rel="nofollow">https://github.com/amacdougall/underscore.as</a>
borntyping超过 12 年前
There is absolutely no reason to use this. As far as I can tell, it's a direct port of underscore.js, and implements nothing but functionality that's already in python.
评论 #4495809 未加载
yoduh超过 12 年前
My opinion: Anytime you share code by posting it publicly, you should always be prepared for negative feedback. In some cases that might be the whole point of posting it: you want to learn from your mistakes.
why-el超过 12 年前
Good job! I know that some of these functions maybe have already occurred to Python developers (map et al), but this probably lead you to a broader understanding of underscore.js itself.
评论 #4495814 未加载
评论 #4495777 未加载
mark_story超过 12 年前
While I can understand this might have been fun from a hacking/building experience, I don't understand why do it. Everything except the micro templating already exists in python.
victorlin超过 12 年前
This doesn't bring anything good to Python. Python can do those things nicely. I can't see any point of this library. Also, underscore already has its meaning in some places, such as for i18n. For example, _('Text to be localized'). Another use of underscore is to store the previous output in console. Although you can rename it, still, it's pointless.
sontek超过 12 年前
I think the biggest benefit of this is having the template language ported to python so you can use the same templates server side or client side.
评论 #4496271 未加载
cpylua超过 12 年前
Collection functions are not that useful in Python. For Function functions I'd prefer using decorators.
评论 #4496316 未加载