Question:I’ve read numerous posts on this, and I realise lots of people have asked this, but I can’t understand what I’m doing wrong. I’m trying to draw a grid with coordinates for a project I’m working on, and I was trying some code for generating it. I tryed this one, but I keep getting that error. What’s wrong with the code? I’ve tryed different indentations but it doesn’t work.
^^The original q+a
Thanks to everyone who helped, I’m not sure why that code was posted considering it wouldn’t work anyway! Sorry for my misunderstanding, I haven’t used generators before. 🙂
yieldkeyword is used to “return” a generator object from a function
Stack Overflow Question on the yield keyword
It cannot be used outside a function, like in your code.
If this was under a
defstatement, then it would be fine, however there is no
defstatement here, so it raises an error
Also, not in relation to the question, but these lines won’t work:
stepsizeis a float, and the
rangefunction only handles integers – it will say something like
TypeError: 'float' object cannot be interpreted as an integer
If you have better answer, please add a comment about this, thank you!