+ 2
Strange Brython error with sub-generators
I have tried to use sub-generators in Brython and am getting a strange error. https://code.sololearn.com/WNMwvM81s4dZ/?ref=app In regular Python, this runs without problems. Has anyone encountered this and knows what it means or how to make this work?
6 Respostas
+ 4
Strange. To me it looks like brython is split into modules and it's trying to load more brython code into your browser at runtime, but there it fails.
Looks like it's a cdnjs issue, it's complaining that sololearn.com is trying to access a file at cdnjs.cloudflare.com—a cross-origin request—and that that particular file is not cross-origin-requestable. Maybe the brython people have misconfigured something too.
Maybe try including brython from another cdn? I'd also open an issue on their github.
EDIT: Running via `https://cdn.jsdelivr.net/npm/brython@3.8.7/brython.min.js` yields a 404 for the same file, sys.py. That definitely indicates that brython is like, hella buggy mate.
Just kidding. But it's not cdnjs, opening an issue on brython's github sounds like the right thing to do.
+ 3
I found this open issue.
https://github.com/brython-dev/brython/issues/771
The code is different but the symptom (error message) looks very similar. So you could try the webview quickfix mentioned in those comments, maybe it helps.
+ 3
Schindlabua, Mirielle👽, Tibor Santa, thank you, guys, for looking into this with me!
Tibor, I have taken your battleship code and used the setup there, including the stdlib and setting Brython's instantiation parameters like you did (without knowing yet what it means).
And funnily enough: It seems to work!
(You can click at the link above to see.)
So it looks as if Brython, for using yield from, needs to import from the stdlib, and needs to be given the permission to do so...
I had already found away around using yield from, but it was a bit sad, because I had finally found a use case for sub generators. 😉
+ 2
"yield from" seems bugged indeed..
One more thing you could try is get the latest source code from github and download, and check it locally. Then you can make sure it is not a cdn issue...
+ 1
A bit offtopic, but for uses of yield from, I found out it useful to parse. I used it as a solution to recursively parse a json file. Is the only case that I have needed it.