简体   繁体   中英

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]

热敏

建立系统档案

问题

终端的Python版本

Are you sure that you are using Python 3? Because Python 2 returns 1 and Python 3 returns 1.5 在此处输入图片说明


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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM