S. Li
S. Li

Reputation: 777

Unexpected results for Python expressions

I use Sublime Text(the latest version) as the Python editor. But there are some issues. First, I have Python 3.6.1 on my MAC. But this division doesn't work properly in Sublime Text.

For example, when I type

print(3/2)

The result should be 1.5, but it shows 1 instead.

And another one, when I use set,

course = {'Math', 'English', 'Digital Circuit Design', 'Python'}
print(course)

The result is also a little weird.

set(['Python', 'English', 'Math', 'Digital Circuit Design'])

Is there some kind of configuration setting or something?

Update

When I build with the new build system, then it shows this following:

[Errno 2] No such file or directory: 'python3'

[cmd: ['python3', '-u', '/Users/L/Desktop/Python/Tutorial3.py']]

[dir: /Users/L/Desktop/Python]

[path: /usr/bin:/bin:/usr/sbin:/sbin]

[Finished]

Therminal

build system file

issue

Python version of terminal

Upvotes: 0

Views: 108

Answers (1)

Ferit
Ferit

Reputation: 9647

Are you sure that you are using Python 3? Because Python 2 returns 1 and Python 3 returns 1.5 enter image description here


If your Sublime does use Python 2 build options (default is Python 2), you can change it to Python 3 like this:

  1. Tools > Build System > New Build System

  2. Use following configuration to declare a new build system.

    {
        "cmd": ["python3", "-u", "$file"],
        "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
        "selector": "source.python"
    }
    
  3. Build with this new system.

Done.

Read also: http://docs.sublimetext.info/en/latest/file_processing/build_systems.html


Extra troubleshooting from comments with help of AdamSmith:

If you get such an error: [Errno 2] No such file or directory: 'python3'

Try replacing python3 part of the configuration with full path. You can find full path by which python3 command.

Upvotes: 3

Related Questions