Home Download Buy Blog Forum Support

ST3 error with simple print "hello"

ST3 error with simple print "hello"

Postby mrmccormack on Thu Jul 18, 2013 4:44 pm

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

Code: Select all
view.run_command("example")


Here is very simple example:
Code: Select all
import sublime, sublime_plugin

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


Error
Code: Select all
    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
mrmccormack
 
Posts: 18
Joined: Wed Jul 17, 2013 4:28 pm

Re: ST3 error with simple print "hello"

Postby weslly on Thu Jul 18, 2013 4:58 pm

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

Code: Select all
# Python 2
print "hello"

# Python 3
print("hello")


http://www.harshj.com/2008/12/09/the-ne ... -python-3/
weslly
 
Posts: 203
Joined: Sun Aug 28, 2011 3:57 am
Location: Brazil

Re: ST3 error with simple print "hello"

Postby mrmccormack on Thu Jul 18, 2013 7:18 pm

Hey thanks for answer and link.

I just noticed the move to Python 3.3 with Sublime Text 3:
http://www.sublimetext.com/docs/3/porting_guide.html
and that
Furthermore, on OS X, the system build of Python is no longer used, instead Sublime Text is bundled with its own version. Windows and Linux are also bundled with their own version, as they were previously.


Which explains what happened.

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

Code: Select all
# Python 3 AND Python 2
print ("hello")


Rob
mrmccormack
 
Posts: 18
Joined: Wed Jul 17, 2013 4:28 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 23 guests