本文介绍了itertools to iter transition(WAS:Pre-PEP:Dictionary accumulatormethods)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

杰克·迪德里奇写道:




很酷的主意。我认为转换自

itertools.XXX(可迭代,* args,** kwargs)



iter.XXX(可迭代,* args,** kwargs)

应该很容易。从这里过渡到

iter(可迭代).XXX(* args,** kwargs)

看起来似乎可能更复杂 - 它必须

返回一个代理对象而不是__iter __ [1]返回的对象。我猜测它已经为那些仅支持__getitem__

协议的对象做了,所以也许它不是那么糟糕......


STeVe


[1]你可能也想要特殊情况,这样如果它()

是调用了一个已经是iter实例的对象,即

对象本身被返回,而不是代理。



Very cool idea. I think the transition from
itertools.XXX(iterable, *args, **kwargs)
to
iter.XXX(iterable, *args, **kwargs)
ought to be pretty easy. The transition from here to
iter(iterable).XXX(*args, **kwargs)
seems like it might be more complicated though -- iter would have to
return a proxy object instead of the object returned by __iter__[1]. I
guess it already does that for objects that support only the __getitem__
protocol though, so maybe it''s not so bad...

STeVe

[1] And you''d probably also want to special-case this so that if iter()
was called on an object that''s already an instance of iter, that the
object itself was returned, not a proxy.

推荐答案




我只包括使它成为一种类型,使其更加对称,因为

是一种类型。 iter目前是一个函数,作为一个实际的问题,如果它作为命名空间加倍但我可能不会想到它会让别人退缩。

[1]而你'd可能也想要特殊情况这样,如果iter()
在一个已经是iter实例的对象上被调用,那么
对象本身被返回,而不是代理。



I only included making iter a type to make it more symmetric with str
being a type. iter is currently a function, as a practical matter I wouldn''t
mind if it doubled as a namespace but that might make others flinch.
[1] And you''d probably also want to special-case this so that if iter()
was called on an object that''s already an instance of iter, that the
object itself was returned, not a proxy.






iter拥有当前作为itertools中的方法存在的属性

对我来说听起来不错。


我真的不喜欢它作为一种类型而不是函数但是。它乍看起来好像是一个很酷的主意,但是你想想它并且

意识到(与任何类名不同)iter(x)几乎是

永远不会返回那种类型的物体。


-

David Eppstein

大学计算机科学系加利福尼亚州,Irvine




[Steven Bethard]很酷的主意。我认为从
itertools.XXX(可迭代,* args,** kwargs)过渡到
iter.XXX(可迭代,* args,** kwargs)
应该很简单。


[Steven Bethard] Very cool idea. I think the transition from
itertools.XXX(iterable, *args, **kwargs)
to
iter.XXX(iterable, *args, **kwargs)
ought to be pretty easy.




只是为了确保你们能够接受你提出的语法,尝试使用它b / b
一个月左右报告经验是否令人愉快。试试

将以下内容放入你的setup.py


import __builtin __,itertools

orig = __builtin __。iter

def iter(* args):

return orig(* args)

for name in( ''__doc__'',''_ _ 1 _''):

setattr(iter,name,getattr(orig,name))

vars(iter).update(vars (itertools))

__builtin __。iter = iter

wrapiter()


如果体验有效,那么你所有的' 留下来是琐碎的事情

令人信服的Guido,功能属性是确定治愈

输入进口报表的负担。

Raymond Hettinger



Just to make sure you guys can live with your proposed syntax, trying using it
for a month or so and report back on whether the experience was pleasant. Try
dropping the following into your setup.py

def wrapiter():
import __builtin__, itertools
orig = __builtin__.iter
def iter(*args):
return orig(*args)
for name in (''__doc__'', ''__name__''):
setattr(iter, name, getattr(orig, name))
vars(iter).update(vars(itertools))
__builtin__.iter = iter
wrapiter()

If the experience works out, then all you''re left with is the trivial matter of
convincing Guido that function attributes are a sure cure for the burden of
typing import statements.
Raymond Hettinger


这篇关于itertools to iter transition(WAS:Pre-PEP:Dictionary accumulatormethods)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 09:00