itertools to iter transition(WAS:Pre-PEP:Dictionary accumulatormethods) [英] itertools to iter transition (WAS: Pre-PEP: Dictionary accumulatormethods)

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

问题描述

杰克·迪德里奇写道:


迭代过渡到了它,是吧?我把那个放进去了,我在PyCon上向Raymond提到了它,他并没有退缩。很高兴不要在代码中使用''import itertools'。 iter也可以成为一个类型包装而不是一个函数,所以iter实例可以成为一个包装器,根据它的参数确定是否调用.next或__getitem__

对于iter(mylist)中的项目.imap:
对于iter.imap(mylist)中的项目打印项目


打印项目

itertools to iter transition, huh? I slipped that one in, I mentioned
it to Raymond at PyCon and he didn''t flinch. It would be nice not to
have to sprinkle ''import itertools as it'' in code. iter could also
become a type wrapper instead of a function, so an iter instance could
be a wrapper that figures out whether to call .next or __getitem__
depending on it''s argument.
for item in iter(mylist).imap:
print item
or
for item in iter.imap(mylist):
print item




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

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.

推荐答案

2005年3月28日星期一上午10:28:29 -0700,Steven Bethard写道:
On Mon, Mar 28, 2005 at 10:28:29AM -0700, Steven Bethard wrote:
Jack Diederich写道:
Jack Diederich wrote:

itertools to过渡,是吧?我把那个放进去了,我在PyCon上向Raymond提到了它,他并没有退缩。很高兴不要在代码中使用''import itertools'。 iter也可以成为一个类型包装而不是一个函数,所以iter实例可以成为一个包装器,根据它的参数确定是否调用.next或__getitem__

对于iter(mylist)中的项目.imap:
对于iter.imap(mylist)中的项目打印项目


打印项目
非常很酷的主意。我认为从
itertools.XXX(可迭代,* args,** kwargs)过渡到
iter.XXX(可迭代,* args,** kwargs)
应该很容易从这里过渡到
iter(可迭代).XXX(* args,** kwargs)
似乎可能会更复杂 - 它必须返回代理对象而不是__iter __ [1]返回的对象。我猜它已经为那些仅支持__getitem__
协议的对象做了,所以也许它不是那么糟糕......

itertools to iter transition, huh? I slipped that one in, I mentioned
it to Raymond at PyCon and he didn''t flinch. It would be nice not to
have to sprinkle ''import itertools as it'' in code. iter could also
become a type wrapper instead of a function, so an iter instance could
be a wrapper that figures out whether to call .next or __getitem__
depending on it''s argument.
for item in iter(mylist).imap:
print item
or
for item in iter.imap(mylist):
print item
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...




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

是一种类型。 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.



在文章< ma ************************* ************@python.or g>,

Jack Diederich< ja ** @ performancedrivers.com>写道:
In article <ma*************************************@python.or g>,
Jack Diederich <ja**@performancedrivers.com> wrote:
我只包括使它成为一种类型,使其更加对称,str
是一种类型。 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.




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

对我来说听起来不错。


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

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

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


-

David Eppstein

大学计算机科学系加利福尼亚州,Irvine
http://www.ics.uci。 edu /~eppstein /


[Jack Diederich]
[Jack Diederich]
> itertools to iter transition,是吗?我把那个放了进去,我提到了
>在PyCon的雷蒙德,他并没有退缩。
>会很高兴。必须在代码中撒上''import itertools'。 iter也可以
>成为一个类型包装而不是一个函数,所以iter实例可以
>是一个包装,确定是否要调用.next或__getitem__
>取决于它的论点。
>对于iter中的项目(mylist).imap:
>打印项目
>或
>对于iter.imap(mylist)中的项目:
>打印项目
> itertools to iter transition, huh? I slipped that one in, I mentioned
> it to Raymond at PyCon and he didn''t flinch. It would be nice not to
> have to sprinkle ''import itertools as it'' in code. iter could also
> become a type wrapper instead of a function, so an iter instance could
> be a wrapper that figures out whether to call .next or __getitem__
> depending on it''s argument.
> for item in iter(mylist).imap:
> print item
> or
> for item in iter.imap(mylist):
> print item



[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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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