Python Forum
Using Generators and their expressions
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Generators and their expressions
#1
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)) 
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)
Reply


Messages In This Thread
Using Generators and their expressions - by BeerLover - Mar-17-2017, 11:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Statements and Expressions Julie 1 1,642 Feb-26-2021, 05:19 PM
Last Post: nilamo
  Regular Expressions pprod 4 3,093 Nov-13-2020, 07:45 AM
Last Post: pprod
  Regular Expressions amitalable 4 2,780 Mar-14-2019, 04:31 PM
Last Post: DeaD_EyE
  2 iterators or generators Skaperen 1 33,549 Jan-04-2018, 07:41 AM
Last Post: Gribouillis
  Stacking generators Ofnuts 2 19,646 Sep-18-2016, 08:36 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020