- BOFH借口#308: CD-ROM服务器需要重新校准 Hi,The function len() is not mentioned in the Python 3000 PEPs.I suggest that at least lists, tupples, sets, dictionaries and stringsget a len() method. I think the len function can stay, removing itwould break to much code. But adding the method, would bu usefull.Yes, I know, that I can call .__len__() but that is ugly.I have read the FAQ to the len function: http://www.python.org/doc/faq/genera...r-e-g-len-list--Thomas Güttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/E-Mail: guettli (*) thomas-guettler + deSpam Catcher: ni**************@thomas-guettler.de 解决方案Why?That''s what len() is for.Regards,Bj?rn--BOFH excuse #281:The co-locator cannot verify the frame-relay gateway to the ISDNserver.Why?Pro: Because it makes the API more monotonous and more aligned with allother OO languages that exist now and in future. It also helps anywritten and unwritten IDE providing a method by means ofautocompletion. It ends endless debates with Java/C++/C# etc. andnewbie Python programmers about this minor issue.Contra: Having both __len__ ( for providing a generic function byduality ) and len in the API is unpleasant.But maybe one can drop all __special__ methods and use a decorator toexpress duality between methods and functions?class M:@genericdef foo(self):print "foo""foo"And since we are at it. Why not also dropping __add__, __radd__,__plus__ etc. for:class M:def binary+(self, other): # replaces __add__...def r_binary+(self, other): # replaces __radd__...def unary+(self, other): # replaces __plus__...Contra: It makes the API more aligned with some other OO languagesand moves the focus from "the python way" to "the way it''s alwaysbeen done".Regards,Bj?rn--BOFH excuse #308:CD-ROM server needs recalibration 这篇关于len()和PEP 3000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 04:27