在sublime中直接运行python代码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012247418/article/details/82960672

系统:win10

编辑器:sublime TXT 3

---------------------------------

有两种方法可以在sublime中直接运行python代码。

1)非交互式程序写完代码保存后直接按ctrl+B,如只有输出的程序。

2)交互式程序需要下载SublimeREPL,如需要输入的的程序。

1. 非交互式程序

1)设置:

工具(tool)-->编译系统(build-system)-->设置为自动,或者直接选择python

2)编辑代码

print("hello python.")

保存为test.py

3)执行

按ctrl+B,可在sublime界面下方弹出结果。

注:确保已经正确配置好python的环境变量(PATH)

2. 交互式环境

准备代码,保存为test.py

msg = input("please input: ")

print("output: ", msg)

1)按ctrl+shift+p快捷键呼出一个输入框,输入Install Package,回车,在新出现的输入框里输入SublimeREPL安装。

2)点击Tools->sublimeREPL->python->python run current file,这时候就像IDLE一样,会弹出一个新的窗口,而且是可交互的,可以输入。

3)结果:

4)设置快捷键

点击preferences->key bindings

添加:

{ "keys":["f5"],

"caption": "SublimeREPL: Python - RUN current file",

"command": "run_existing_window_command",

"args": {"id": "repl_python_run","file": "config/Python/Main.sublime-menu"}

}

重启sublime,现在可以直接按F5来运行。

猜你喜欢

转载自blog.csdn.net/u012247418/article/details/82960672