Sublime Forum

python3 print("Hello Wold", end=" ") give an error

#1

Hello There,

In sublime Text 3 Build 3059 the following code give me an error:

[code]#!/usr/bin/python3

print(“Hello world”, end=" ")[/code]

Give me this when I press CTRL+b

File "/home/user2/Python/test.py", line 3 print("Hello world", end=" ") [Finished in 0.0s with exit code 1] [shell_cmd: python -u "/home/user/Python/test.py"] [dir: /home/user/Python/] [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games] ^ SyntaxError: invalid syntax

In a shell it works fine.

I’m runing it on Linux on python 3.4

Is this a bug?

0 Likes

#2

[quote=“Langlais”]Hello There,

In sublime Text 3 Build 3059 the following code give me an error:

[code]#!/usr/bin/python3

print(“Hello world”, end=" ")[/code]

Give me this when I press CTRL+b[/quote]

ST comes with a own python and for Ctrl+B you have to create/adjust the build system file.

See

sublime-text-unofficial-document … stems.html

[code]File Format

Build systems are JSON files and have the extension .sublime-build.

Example

Here’s an example of a build system:

{
“cmd”: “python”, “-u”, “$file”],
“file_regex”: “^ ]File "(…?)”, line ([0-9]*)",
“selector”: “source.python”
}

[/code]

.

0 Likes

#3

Hi Jim,

Thank you for your answer, that was helpful.

Now I’ve created my file python3.sublime-build

{ "linux": { "cmd": "python3", "-u", "$file"], "file_regex": "^ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.py" } }

and past it in the User folder that I’ve create under Packages
/opt/sublime_text/Packages/User

Restart Sublime Text.
But it doesn’t appear in the Tools > Build System menu. The permisions are correct as I used the same as the Packages one.

Am I missing something?

0 Likes

#4

It shows up for me.

Perhaps you have stored it in the wrong path?
I guess the folder “User” should exist already? No need for create it yourself? (I may be wrong here)

Check “Preferences > Browse Packages…” to open the right folder.

Then, below of “User” you can create a new sub folder named “Builds” (or what you want) to organize the files.

Immediately there should be that new build system visible under “Tools > Build System” menu.
A restart of ST should not be necessary to show the change.

.

0 Likes

#5

Ok, thanks.
Now I see it and I can execute my code using python3. :laughing:

But now, it’s the function input that doesn’t seems to be supported … :open_mouth:

Here is my code:

#!/usr/bin/python3 import sys print (sys.version) print("Please type something:" , end=" ") userInput = input() print("User Input is: ", userInput)

Here is the result in sublime (build 3059):

3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] Please type something: Traceback (most recent call last): File "/home/user/Python/test.python", line 5, in <module> userInput = input() EOFError: EOF when reading a line [Finished in 0.2s with exit code 1] [cmd: ['/usr/bin/python3', '-u', '/home/user/Python/test.python']] [dir: /home/user/Python/] [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]

and here is the result in the shell:

user@Desktop:~/Python/$ ./test.python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] Please type something: test User Input is: test user@Desktop:~/Python/$ user@Desktop:~/Python/$ user@Desktop:~/Python/$ which python3 /usr/bin/python3 user@Desktop:~/Python/$

How come can I get 2 diffrent result with the same interpreter?
Does sublime is modifying the code before passing it to the interpreter?

Although the problem describe in the first post was not a bug.
Here, I’m not sur that this one isn’t one !!! :neutral_face:

0 Likes

#6

Where would you have access to that input() request from within ST?
I guess there is no interactive between ST and python console.

Rather I would consult the ST API and use an ST command to get user input:

[quote]
show_input_panel(caption, initial_text, on_done, on_change, on_cancel)

View Shows the input panel, to collect a line of input from the user. on_done and on_change,
if not None, should both be functions that expect a single string argument. on_cancel should
be a function that expects no arguments. The view used for the input widget is returned.[/quote]

https://www.sublimetext.com/docs/3/api_reference.html

Me guess it should be something like:

[code]import sublime, sublime_plugin, sys

class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
print (sys.version)
print(“Please type something:” , end=" ")
userInput = self.view.window().show_input_panel(caption, initial_text, on_done, on_change, on_cancel)
print("User Input is: ", userInput)[/code]http://sublimetext.info/docs/en/extensibility/plugins.html

You should browse the forum or google for some code examples to get how it works, as I do currently.

0 Likes