# PyGen - python style generators

**URL:** <https://discourse.julialang.org/t/pygen-python-style-generators/3451>\
**Category:** Community\
**Tags:** package, announcement\
**Created:** [May 1, 2017, 4:09am UTC](https://discourse.julialang.org/t/pygen-python-style-generators/3451 "2017-05-01T04:09:29Z")\
**Posts on this page:** 1\
**Showing post:** 56

<div class="post-metadata">

**Author:** ![o314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/o314/32/252_2.png) [@o314](https://discourse.julialang.org/u/o314)\
**Post date:** [January 16, 2019, 3:13am UTC](https://discourse.julialang.org/t/pygen-python-style-generators/3451/56 "2019-01-16T03:13:40Z")

</div>

@BenLauwens

Very Great work !

However i’am not so fond of solutions that shake the runtime at a too low level with some kind of magical macro on a general basis.

So i have handcoded my yield

```julia
struct PSerie
    p
end

function Base.iterate(ps::PSerie, itr=(0,1,0))
    s,n,y = itr
    if y == 1; @goto y1 end

    while true
        s += 1.0/(n^ps.p)
        return s,(s,n,1)
        @label y1
        n += 1
    end
end

```

And you can too

More info here:

> [@Creating Generators](https://discourse.julialang.org/t/creating-generators/3962/14):
>
> Suppose you have this in python # aka riemann serie def p\_serie(p): assert(p\>0) s = 0 n = 1 while True: s += 1.0/pow(n,p) yield s n += 1 then run itr = p\_serie(2) [next(itr) for \_ in range(10)] that output (reformatted) [1.0, 1.25, 1.3611111111111112, 1.4236111111111112, 1.4636111111111112, 1.4913888888888889, 1.511797052154195, 1.527422052154195, 1.5397677311665408, 1.5497677311665408] (1/2)

---

_[View the full topic](https://discourse.julialang.org/t/pygen-python-style-generators/3451)._
