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 would try something a bit more explicit like this, this matches your expected answer</p>

<pre><code>import itertools

def calculate_length(x0, x1, y0, y1):
    return ((x1 - x0)**2+(y1 - y0)**2)**.5

def make_point_pairs(poly):
    pairs = zip(poly, poly[1:])
    # Close the shape
    chain = itertools.chain(pairs, [[poly[-1],poly[0]]])
    return chain

def perimeter(poly):
     return sum([calculate_length(x0, x1, y0, y1) for ((x0, y0), (x1, y1)) in make_point_pairs(poly)])
</code></pre>

python python-3.x generator