Mar-17-2017, 11:33 PM
(This post was last modified: Mar-18-2017, 01:19 AM by ichabod801.)
I am trying to get my head around generators. I do not really understand the concept of generators and their expressions, however I read what they are used for and it seems that I might need them going further when learning Python (3.6).
There is this code. And the printing just won't work:
(Python 3.6 (spyder3))
There is this code. And the printing just won't work:
(Python 3.6 (spyder3))
def simple_generator_function(): yield 1 yield 2 yield 3 our_generator = simple_generator_function() for i in list(our_generator): print((i))
Output:Error:
File "...\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
...
print((i))
UnsupportedOperation: not writable
Why can not I print this iterable object? (print(list(i)) doesn't work either)