Sublime Forum

Python .join not working?

#1

Hello,

I have just installed Python and have set both build and syntax to Python. I am learning Python, using Codeacademy to get me started. The following code runs fine at Codecademy’s website, but when I put it into Sublime Text 2, I get a syntax error.

Here’s the code:

[code]board = ]
for item in range(0,5):
board.append(“O”] * 5)

def print_board(board):
for row in board:
print " ".join(row)

print_board(board)[/code]

and here’s what returns in the console:

[quote] File “C:\Users[myusername]-- Computer Learning\Python Learning\PythonTest.py”, line 7
print " ".join(row)
^
SyntaxError: invalid syntax[/quote]

(In case the format gets off, the caret (^) is lined up under the second quotation mark, just before the period (.)

Why would it not work? Do I have to import a library or anything?

Thanks for any help!

PS: I am on Windows 7, 64 bit. I have added the Python path to PATH in Advanced System Settings, and can run Python from cmd.exe.

0 Likes

#2

This isn’t a ST issue, it looks like you’ve installed Python 3.x and in Python 3 you have to use parenthesis for print.

print " ".join(row) # Python 2.x
print(" ".join(row)) # Python 3.x
0 Likes

#3

[quote=“subhaze”]This isn’t a ST issue, it looks like you’ve installed Python 3.x and in Python 3 you have to use parenthesis for print.

print " ".join(row) # Python 2.x print(" ".join(row)) # Python 3.x [/quote]

! That’s it, thank you very much! :mrgreen:

0 Likes