Just Starting - Invalid Syntax in the Manual?

Hello; I have just started fumbling my way through the Panda Manual, and already I have come across something I can’t do. I am on the “Controlling the Camera” page for the Python language, and whenever I run my file from a console, it says I am using invalid syntax. In case it matters, I have Panda 1.7.0, and Python 2.6.1, though I doubt it matters since the other examples so far have been working fine. Here is the line in question:

self.camera.setHpr(angleDegrees, 0, 0)

My command prompt tells me that this line contains invalid syntax. But how can this be? The first and second times, I typed it exactly as shown; the third time I copied it and pasted it directly from the manual itself, yet I’m still getting a syntax error. Why is this? Up until now, the examples have run fine.

There is a little circumflex accent under the f in self, which, given what happens when I consciously make a syntax error and observe the results, seems to imply that the error is with the f, or one of the characters next to it. There appears to be a slight space after the f in the command prompt, but this space is definately not present in the file itself; I have erased and manually rewritten it a couple of times, and the error keeps cropping up. Any help, hints and advice are appreciated!

This seems to be a question from the Python-newbie category. There is nothing wrong with the syntax itself. Can you copy the full output from your console to a post? For example something like this:

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 <>> 2
  File "<stdin>", line 1
    1 <>> 2
SyntaxError: invalid syntax

I’d bet you a dollar that it’s an indentation problem. Python is very fussy about lining up your lines correctly, and it’s the first thing that trips up most newcomers to Python.


Especially if you copy and paste. It’s such a pain to fix the indentations (at least in Notepad2) that I should have just typed it instead.

Well, I solved it, but I’m still not sure what it was. See, I had originally copy-pasted only the new section when trying to fix it; the block that made the camera turn. But then in despair I copy-pasted the whole program into my editor from the manual, and suddenly it worked fine.

As it did this, I noticed something change above the new block, which led me to believe that the mistake might possibly have been on another line, though that seemed strange. When I went did an “undo” to see what changed, though, all that was different was something that was within a comment, which should have affected the code. So I don’t really know what it was - it probably was an indentation, like you say. Anyways, thanks for the help!