0
data = open('sketch.txt')

for each_line in data:
    try:
        (role, line_spoken) = each_line.split(':', 1)
        print(role, end='')
        print(' said: ', end='')
        print(line_spoken, end='')
    except:
        pass

data.close()

I'M gettin the following error when I run this code but it looks exactly like what I'M seeing in my Head First book.

File "sketch.py", line 6
    print(role, end='')
                   ^
SyntaxError: invalid syntax


------------------
(program exited with code: 1)
Press return to continue
5
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by lewashby
1

Add to beginning

from __future__ import print_function

You could use the Python2 style print, but learning Python3 style is worth it as it is more flexible and compatible with Python3.

0

Your "Head First" book must be using code for Python3. It might be worthwhile to install that version of Python.

Edited by vegaseat: t

1

Don't jump the gun and download Python 3.3 yet, it still has a few bugs.
Download the much more stable Python 3.2

0

Thanks. I do have python3 installed. So how do I point Geany to python3 rather than python 2 which it is currently pointing to. I looked through preferences but couldn't find it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.