标签:style blog http color 使用 os strong 文件
1.下载python并安装
import urllib2,os,hashlib; h =‘7183a2d3e96f11eeadd761d777e62404‘+‘e330c659d4bb41d3bdf022e94cab3cd0‘; pf =‘Package Control.sublime-package‘; ipp = sublime.installed_packages_path(); os.makedirs( ipp )ifnot os.path.exists(ipp)elseNone; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler())); by = urllib2.urlopen(‘http://sublime.wbond.net/‘+ pf.replace(‘ ‘,‘%20‘)).read(); dh = hashlib.sha256(by).hexdigest(); open( os.path.join( ipp, pf),‘wb‘).write(by)if dh == h elseNone;print(‘Error validating download (got %s instead of %s), please try manual install‘%(dh, h)if dh != h else‘Please restart Sublime Text to finish installation‘)
{"command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "d",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
其中id的值是我们需要的,因为我们正是要为其添加快捷键。另外,菜单文件的位置也是需要先记下的,因为需要为这个命令指定定义的来源。
3.Preferences => Key Boundings-User打开自定义快捷键文件,写入如下内容:
[
{
"keys" : ["f5"], // 快捷键,注意小写
"command" : "run_existing_window_command", // 运行定义的命令
"args" : // 命令参数
{
"id" : "repl_python_run", // 上一步查看的命令的id
"file" : "config/Python/Main.sublime-menu" // 菜单定义文件位置
}
}
]
到此为止,可以使用快捷键F5在Sublime Text2编辑器中快速执行Python代码。
Sublime Text2配置python环境,布布扣,bubuko.com
标签:style blog http color 使用 os strong 文件
原文地址:http://www.cnblogs.com/izxcheng/p/3873037.html