Monday, 27 January 2020

python yield

yielded items are disposable. They are temporarily stored in memory and cleared after use. 

>>> def f():
...   yield 1
...   yield 2
...   yield 3
...
>>> g = f()
>>> for i in g:
...   print i
...
1
2
3
>>> for i in g:
...   print i
...
>>> # Note that this time nothing was printed

reference:
https://stackoverflow.com/questions/519633/lazy-method-for-reading-big-file-in-python
https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do
https://stackoverflow.com/questions/11218477/how-can-i-use-pickle-to-save-a-dict
https://www.blopig.com/blog/2016/08/processing-large-files-using-python/
https://stackoverflow.com/questions/17749058/combine-multiple-text-files-into-one-text-file-using-python/17749339
https://wiki.python.org/moin/UsingPickle
https://stackoverflow.com/questions/18388368/create-file-in-sub-directory-python

No comments:

Post a Comment