一个Python 3000问题 [英] A Python 3000 Question

查看:62
本文介绍了一个Python 3000问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

len(a_string)会变成a_string.len()吗?我刚刚阅读了

http: //docs.python.org/dev/3.0/whatsnew/3.0.html

与其他OO语言相比,Python的一个批评是

它不够OO或OO与其他人或它不一致。并且

这样的小事似乎支持这些论点。并不是说它真的很重要......似乎在一个OO语言中,以更符合b / b
的方式使用方法的类更合适。有没有

a因为len不能成为一种方法?


a_string.lower()是有意义的,a_string.split(),

a_string.strip()...为什么不是a_string.len()?

Will len(a_string) become a_string.len()? I was just reading

http://docs.python.org/dev/3.0/whatsnew/3.0.html

One of the criticisms of Python compared to other OO languages is that
it isn''t OO enough or as OO as others or that it is inconsistent. And
little things such as this seem to support those arguments. Not that it
matters really... just seems that classes with methods used in a more
consistent manner would be more appropriate in an OO langauage. Is there
a reason that len cannot be a method?

a_string.lower() makes sense, as does a_string.split(),
a_string.strip()... why not a_string.len()?

推荐答案

brad< by ***** **@gmail.comwrites:
brad <by*******@gmail.comwrites:

len(a_string)会变成a_string.len()吗?我刚刚阅读了

http: //docs.python.org/dev/3.0/whatsnew/3.0.html

与其他OO语言相比,Python的一个批评是

它不够OO或OO与其他人或它不一致。并且

这样的小事似乎支持这些论点。不是那个

这真的很重要......似乎用一种方式使用的方法更加一致的方式更符合OO

langauage。有没有理由len不能成为一种方法?


a_string.lower()是有意义的,a_string.split(),

a_string.strip ()...为什么不是a_string.len()?
Will len(a_string) become a_string.len()? I was just reading

http://docs.python.org/dev/3.0/whatsnew/3.0.html

One of the criticisms of Python compared to other OO languages is that
it isn''t OO enough or as OO as others or that it is inconsistent. And
little things such as this seem to support those arguments. Not that
it matters really... just seems that classes with methods used in a
more consistent manner would be more appropriate in an OO
langauage. Is there a reason that len cannot be a method?

a_string.lower() makes sense, as does a_string.split(),
a_string.strip()... why not a_string.len()?



我想知道为什么人们总是抱怨'len`函数但是从来没有关于`iter`或`pprint.pprint`的
? :)


并回答这个问题。在OO编程中,泛型函数

并不比类和对象重要。


问候,

Rob

I wonder why people always complain about `len` function but never
about `iter` or `pprint.pprint`? :)

And to answer the question. In OO programming generic functions
are no less important than classes and objects.

Regards,
Rob


Rob Wolfe写道:
Rob Wolfe wrote:

我想知道为什么人们总是抱怨`len`功能但从来没有

关于`iter`或`pprint.pprint`? :)
I wonder why people always complain about `len` function but never
about `iter` or `pprint.pprint`? :)



不抱怨。 len非常简单易懂,IMO非常合适

with split(),strip()等......这就是为什么我用它作为例子,但

list()等也可以用作例子:


a_string.list()而不是list(a_string)

Not complaining. len is simple and understandable and IMO fits nicely
with split(), strip(), etc... that''s why I used it as an example, but
list(), etc. could be used as examples as well:

a_string.list() instead of list(a_string)


并回答这个问题。在OO编程中,泛型函数

并不比类和对象重要。
And to answer the question. In OO programming generic functions
are no less important than classes and objects.



它们是否不会影响整体语言的OOness和

引入不一致?

Do they not take away from the OOness of the overall language and
introduce inconsistencies?




" brad" < by ******* @ gmail.comwrote in message

news:fg ********** @ solaris.cc.vt.edu ...

|请问len(a_string)成为a_string.len()吗?


No.


我刚读完

| http://docs.python.org/dev/3.0/ whatsnew / 3.0.html


除了一个相反的

方向之外,没有说明这样的改变:o.next()更改为next(o),然后调用o .__ next __(),

就像len(o)调用o .__ len __()


|与其他OO语言相比,Python的一个批评是

|它不是OO足够的或OO与其他人不一致或者它不一致。


Python是基于对象的,并且有一个很好的用户定义类型(类)系统,但是

我不相信Guido曾经称它为面向对象。所以

比较除了这一点之外,即使是真的。


|有没有理由说len不能成为一种方法?


它对应于并调用方法.__ len__,当存在时。是的,

Python的设计可能不同,没有内置函数,但是

不是。 Python也是一种具有一流通用

功能的函数式语言。


|为什么不是a_string.len()?


如果你愿意,可以直接绕过内置函数并直接调用方法:

a_string .__ len __()。


但是考虑改写以下内容:


def table(func,seq):

return zip(seq,map (func,seq))


表(len,('''',(),[]))


如果你*真的*想成为超级OO,就像无功能的OO语言一样,你可以调用方法而不是使用运算符符号,这实际上是

是内置函数的名称。


而不是+ b,写一个.__ add __(b)。等等。


Terry Jan Reedy


"brad" <by*******@gmail.comwrote in message
news:fg**********@solaris.cc.vt.edu...
| Will len(a_string) become a_string.len()?

No.

I was just reading
| http://docs.python.org/dev/3.0/whatsnew/3.0.html

which says nothing about such a change, except for one in the opposite
direction: o.next() changes to next(o) which in turn calls o.__next__(),
just as len(o) calls o.__len__()

| One of the criticisms of Python compared to other OO languages is that
| it isn''t OO enough or as OO as others or that it is inconsistent.

Python is object-based and has a nice user-defined type (class) system, but
I do not believe Guido has ever called it object oriented. So the
comparision is besides the point even if true.

| Is there a reason that len cannot be a method?

It corresponds to and calls method .__len__ , when such exists. Yes,
Python could have been designed differently, with no builtin functions, but
is was not. Python is also a functional language with first-class generic
functions.

| why not a_string.len()?

You are free to bypass builtins and call methods directly if you like:
a_string.__len__().

But consider rewriting the following:

def table(func, seq):
return zip(seq, map(func,seq))

table(len, ('''', (), []))

If you *really* want to be super-OO, like functionless OO languages, you
can also call methods instead of using operator symbols, which in effect
are names of builtin functions.

Instead of a+b, write a.__add__(b). And so on.

Terry Jan Reedy


这篇关于一个Python 3000问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆