Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>join</code> is a method of strings. That method takes any iterable and iterates over it and joins the contents together. (The contents have to be strings, or it will raise an exception.)</p> <p>If you attempt to write the generator object directly to the file, you will just get the generator object itself, not its contents. <code>join</code> "unrolls" the contents of the generator.</p> <p>You can see what is going with a simple, explicit generator:</p> <pre><code>def gen(): yield 'A' yield 'B' yield 'C' &gt;&gt;&gt; g = gen() &gt;&gt;&gt; print g &lt;generator object gen at 0x0000000004BB9090&gt; &gt;&gt;&gt; print ''.join(g) ABC </code></pre> <p>The generator doles out its contents one at a time. If you try to look at the generator itself, it doesn't dole anything out and you just see it as "generator object". To get at its contents, you need to iterate over them. You can do this with a <code>for</code> loop, with the <code>next</code> function, or with any of various other functions/methods that iterate over things (<code>str.join</code> among them).</p> <p>When you say that result "is a list of string" you are getting close to the idea. A generator (or iterable) is sort of like a "potential list". Instead of actually <em>being</em> a list of all its contents all at once, it lets you peel off each item one at a time.</p> <p>None of the objects is a "memory address". The string representation of a generator object (like that of many other objects) includes a memory address, so if you print it (as above) or write it to a file, you'll see that address. But that doesn't mean that object "is" that memory address, and the address itself isn't really usable as such. It's just a handy identifying tag so that if you have multiple objects you can tell them apart.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload