我似乎做了很多(不管是不是我应该或许是另一个话题)在我的Python代码:为*铸造Python的分配速记*
the_list = get_list_generator()
#So `the_list` is a generator object right now
#Iterate the generator pulling the list into memory
the_list = list(the_list)
在做算术作业,我们有速记像这样...
the_number += 1
那么,有什么方法可以在使用函数进行赋值时完成相同的速记。我不知道是否有一个内置的,或者如果我需要定义一个自定义操作符(我从来没有这样做过),或者其他方式,最终导致更清洁的代码(我保证我会只用于泛型类型转换)。
#Maybe using a custom operator ?
the_list @= list()
#Same as above, `the_list` was a generator, but is a list after this line
编辑::
我没有最初提及:这发生在我身上最经常在交互模式(因此为什么我希望削减所需打字)。我会尝试索引一个迭代器gen_obj[3]
,得到一个错误,然后必须施放它。
如所暗示的,这可能是最好的,但最终不是我所期待的。
the_list = list(get_list_generator())
怎么样'the_list =名单(get_list_generator())'? – 2013-04-28 19:14:33