0

I'm try to run a quadtree example (first bit of code on that page) from pygame but am getting a syntax error on a very confusing line:

in_nw = item.left <= cx and item.top <= cy

The syntax error points at the second equals sign in the expression (<=). I know semicolons can be used to put multiple expressions on one line, but wouldn't that mean that this would be the same as:

        in_nw = item.left &lt
        = cx and item.top &lt
        = cy

The problem is, this doesn't make any sense with the leading equals sign. There must be something else going on there. I've spent a couple hours trying to figure this out and reading about compound statements.

Does anyone know what this is suppose to do or a different way of writing it? I assume it worked for the author and the guy who posted a similar code below him with the same syntax, but for some reason it isn't working for me. I really just want to rewrite this part without having to decrypt the rest of his code to figure out what he was trying to do.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Airuno2L
  • 187
  • 7
  • 2
    I assume that's supposed to be `<=`. It looks like the code was messed up somehow when it was inserted into the HTML page, and the symbols were escaped into HTML entity names. – BrenBarn Sep 17 '14 at 19:09
  • 1
    that's python that's been html-encoded, turning all of the `<` into `<` e.g. something's corrupted the code – Marc B Sep 17 '14 at 19:09
  • Wow, thanks everyone! Everyone is right, wish I could mark them all correct. I would have never got that and you all answered so fast I can't even except an answer yet. – Airuno2L Sep 17 '14 at 19:17

2 Answers2

5

This is simply a markup issue. &lt; should be <

The whole line should read:

in_nw = item.left <= cx and item.top <= cy
That1Guy
  • 7,075
  • 4
  • 47
  • 59
3

The syntax is rather strange, for some reason it says &lt instead of the less than sign. This is commonly used HTML and other markup languages where the angle brackets are used for the actual tags, not for less than or greater than.

Replacing the &lt with < and the &gt with > should fix it.

Reed Oei
  • 1,427
  • 2
  • 13
  • 19
  • 2
    Your `<` and `>` were interpreted as HTML entities and turned into `<` and `>`. So you basically fell into the same trap as the guys that wrote that wiki page, just the other way round. (Use backticks to quote them). – Lukas Graf Sep 17 '14 at 19:14