google-code-export / skulpt

Automatically exported from code.google.com/p/skulpt
Other
1 stars 1 forks source link

Feature Request: generator.send #83

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Code you're trying to run:

def mygen(upto):
    for i in range(0, upto):
        print 'i',i
        got = yield i
        print 'got',got

handle = mygen(3)
first = True
for num in handle:
    print 'num',num
    if first:
        print 'signalling'
        foo = handle.send('sig')
        print 'foo', foo
        first = False

What does "real" Python output?

i 0
num 0
signalling
got sig
i 1
foo 1
got None
i 2
num 2
got None

Note that .send(value) also advances the generator (something I'd not 
previously realised)

What browser are you using? On what operating system?
Firefox 3.6.15, Ubuntu Maverick (10.10)

Please provide any additional information.

As far as I know this is not yet implemented in Skulpt, but was added to python 
in 2.5.

Original issue reported on code.google.com by PeterJC...@gmail.com on 18 Mar 2011 at 11:05

GoogleCodeExporter commented 9 years ago

Original comment by sgraham on 19 Mar 2011 at 2:55

GoogleCodeExporter commented 9 years ago
Thanks for the report. Fixed at head, but not on skulpt.org yet.

generator.throw/close are bit more tricky so haven't done those yet. If you 
need those please feel free to open another issue (though they'll take a bit 
more time to get to).

Original comment by sgraham on 19 Mar 2011 at 5:05

GoogleCodeExporter commented 9 years ago
awesome, thanks, having throw & send would be nice, but I don't think essential 
for what I'm doing.

Original comment by PeterJC...@gmail.com on 20 Mar 2011 at 8:41