The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
I’m reading the book Learning Python and having trouble with some of the code examples as soon as it gets to nested statements. The code in the book generates syntax errors when run interactively, but not when I save it as a file and run it. Here’s an example:
Why does 'print 'Bye' generate a syntax error here? I realize that this is probably irrelevant as I don’t really need to run all of the example code, but I’m generally confused as to WTF is going on.
No, I’m not entering typos. I can get a syntax error in the interpreter, copy/paste the failed code to a text file, save the text file, and then run it from the command line with no error. When I run it on my machine it’s always the same interpreter. I also tried running it using the Python interpreter on my remote FreeBSD account on a remote server and I have the same problem there.
I just tried running that in IDLE's interactive mode and it worked perfectly. Are you entering the code into the interpreter exactly as you have it here? If you are, try indenting every line after the "while True" line. That's pretty much the only thing I can think of.
The forums have fubarred the formatting of your code. I assume it is formatted like so in the file you are trying to run:
while True:
reply = raw_input('Enter Text')
if reply == 'stop': break
print reply.upper()
print 'Bye'
I have done the indentation with 4 spaces, not tabs. If your code does look like this I have no idea why it's giving you a Syntax error.
EDIT: Oh, you are getting an error while running it interactively! Sorry, misread what you said. Yeah, I just tried entering the prog into IDLE's interactive shell and it threw a syntax error. Curious. It's an IDLE quirk certainly as I entered it into the python command line interpreter and it worked as expected.
Yeah,it's some bizzare IDLE quirk, when I made the program:
>>> for i in range(0,1):
while True:
reply = raw_input('Enter Text')
if reply == 'stop':
break
print reply.upper()
print "Bye"
It worked as expected without a Syntax Error. Use python24.exe (or whatever version of python you've got) for running stuff interactively, it actually works. Something odd is going on with the final line.
Oh, I misunderstood what the program was supposed to do. I think maybe you can only enter one statement into the interpreter in IDLE at a time. So when you give it a while statement followed by a print statement, it gives a syntax error.
Posts
I have done the indentation with 4 spaces, not tabs. If your code does look like this I have no idea why it's giving you a Syntax error.
EDIT: Oh, you are getting an error while running it interactively! Sorry, misread what you said. Yeah, I just tried entering the prog into IDLE's interactive shell and it threw a syntax error. Curious. It's an IDLE quirk certainly as I entered it into the python command line interpreter and it worked as expected.
Yeah,it's some bizzare IDLE quirk, when I made the program:
It worked as expected without a Syntax Error. Use python24.exe (or whatever version of python you've got) for running stuff interactively, it actually works. Something odd is going on with the final line.
I made a game, it has penguins in it. It's pay what you like on Gumroad.
Currently Ebaying Nothing at all but I might do in the future.
it should work correctly