Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

yield-from

yield from vs yield in for-loop

January 8, 2024 by Tarik

What Happened? When you use next(iter(instance_of_Class2)), iter() calls .close() on the inner generator when it (the iterator, not the generator!) goes out of scope (and is deleted), while with Class1, iter() only closes its instance >>> g = (i for i in range(3)) >>> b = Class2(g) >>> i = iter(b) # hold iterator open … Read more

Categories python Tags generator, python, python-internals, yield, yield-from Leave a comment

Converting “yield from” statement to Python 2.7 code

February 14, 2023 by Tarik

If you don’t use the results of your yields,* you can always turn this: yield from foo … into this: for bar in foo: yield bar There might be a performance cost,** but there is never a semantic difference. Are the entries from the two halves (upper and lower) appended to each other in one … Read more

Categories python Tags generator, python, python-2.x, yield, yield-from Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa