• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: SyntaxError: ‘yield’ outside of function in Python

Resolved: SyntaxError: ‘yield’ outside of function in Python

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

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.
How can I generate a regular geographic grid using python?
^^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. ๐Ÿ™‚

Answer:

The yield keyword 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 def statement, then it would be fine, however there is no def statement here, so it raises an error
Also, not in relation to the question, but these lines won’t work:
because stepsize is a float, and the range function 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!

python yield
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to get Union type from an array of objects in Flow?

24/03/2023

Resolved: Modify entity using Action in C#

24/03/2023

Resolved: How to give rank on datetime column group by another column with userid in it

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.