Sublime Forum

ST3 error with simple print "hello"

#1

I run this fine in ST2, but get error in ST3

Any ideas what is wrong with this most basic example in ST3 ?

I run it by typing into console

view.run_command("example")

Here is very simple example:

import sublime, sublime_plugin

class ExampleCommand(sublime_plugin.TextCommand):
	def run(self, edit):
		self.view.insert(edit, 0, "Hello, World!")
		print "hello"

Error

print "hello" ^ SyntaxError: invalid syntax

Thanks for help…

I wonder if one of my plugins in ST2 is allowing this? I did disable SublimeREPL, but the print still worked in ST2.

Rob

0 Likes

#2

ST3 uses Python 3, and with Python 3, print is a function.

# Python 2
print "hello"

# Python 3
print("hello")

harshj.com/2008/12/09/the-ne … -python-3/

0 Likes

#3

Hey thanks for answer and link.

I just noticed the move to Python 3.3 with Sublime Text 3:
sublimetext.com/docs/3/porting_guide.html
and that

Which explains what happened.

It seems this works in BOTH Python 2 and Pytnon 3, so I can use it in my plugin.

# Python 3 AND Python 2
print ("hello")

Rob

0 Likes