Getting a Generator Object returned when I want the data
<p>I am very very new to Python 3, so please be nice.</p>

<p>I have looked at all the documentation I could find regarding this - there does seem to be a lot, it's just I still cannot figure out what to do.</p>

<p>This is my code:</p>

<pre><code>poly = [[36606.0,53223.0],[37332.0,52224.0],[39043.0,53223.0],
[41603.0,53223.0],[42657.0,53278.0],[43123.0,52060.0],
[44054.0,51156.0],[45806.0,51498.0],[46751.0,53237.0],
[46983.0,54606.0],[45861.0,57057.0],[44971.0,58836.0],
[44054.0,60616.0],[43451.0,58138.0],[41850.0,59179.0],
[40850.0,60370.0],[39906.0,59233.0],[38674.0,59179.0],
[35566.0,56249.0],[37592.0,57536.0]]

def perimeter():
     return (sum((abs((x1 - x0)**2)+abs((y1 - y0)**2))**.5)
                        for ((x0, y0), (x1, y1)) in parts1(poly))

def parts1(poly):
    return poly[0:] + [poly[0]]

print(perimeter())
</code></pre>

<p>It is running <em>without</em> any errors but I am getting a return of:</p>

<p><code>generator object perimeter.locals.genexpr at 0x7f47d8671c50</code></p>

<p>How do I make it so that it gives me the value/answer?
I am really not sure what is going on.</p>

<p>I am also a little confused about your question, it seems that you are not intentionally using the generator and just wants to get the perimeter?
I think it would be better to clean up the function <code>perimeter()</code> a little bit and not use a generator there, and simply iterate through the list <code>poly</code> and taking every adjacent pair and calculate it this way.</p>

<pre><code>poly = [[36606.0,53223.0],[37332.0,52224.0],[39043.0,53223.0],
[41603.0,53223.0],[42657.0,53278.0],[43123.0,52060.0],
[44054.0,51156.0],[45806.0,51498.0],[46751.0,53237.0],
[46983.0,54606.0],[45861.0,57057.0],[44971.0,58836.0],
[44054.0,60616.0],[43451.0,58138.0],[41850.0,59179.0],
[40850.0,60370.0],[39906.0,59233.0],[38674.0,59179.0],
[35566.0,56249.0],[37592.0,57536.0]]

def perimeter():
    #return (sum((abs((x1 - x0)**2)+abs((y1 - y0)**2))**.5) \
                        #for ((x0, y0), (x1, y1)) in parts1(poly))
    peri=0
    for [x0, y0], [x1, y1] in get_pair(poly):
        peri+=((x1-x0)**2 + (y1-y0)**2)**0.5
    return peri

def get_pair(poly):
    i=0
    while i&lt;len(poly):
        yield [poly [i],poly [(i+1)%len(poly)]] #The modulo takes the pair of last and first coordinates into account
        #So that when poly [i] is the last coordinate it is returned with the first coordinate
        i+=1

print(perimeter())
</code></pre>

<p>I used a generator function for <code>get_pair()</code> function, but you can also do it with a loop or some other way. It basically just returns a new pair in the list every time you call it.</p>

python python-3.x generator