我似乎做了很多(不管是不是我應該或許是另一個話題)在我的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