1. 程式人生 > >Python相關

Python相關

python

1.打印當前python版本
import sys
print(sys.version)
2.sublime text 3中添加python3環境
如果linux系統同時安裝python2和python3,但是sublime text3中默認只有python (也就是python2)
打開sublime text 3,點擊上部菜單欄Tools->Build System->new Build System,
點擊後,會打開一個空的配置文件,此時,往這個空配置文件拷貝一下代碼。

{
"cmd": ["/usr/bin/python3", "-u", "$file"],

"file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
"selector": "source.python"
}

其中,/usr/bin/python3 為系統內python3的環境路徑,以linux系統為例,打開一個終端,輸入which python3,即可顯示python3所在路徑,前提是系統已經安裝了python3.示例:
xueyeu8@Presario-CQ42:~/桌面$ which python3
/usr/bin/python3
保存配置文件,命名為Python3.sublime-build. 點擊保存即可(默認保存位置即可)

之後可以在Tools->Build System裏選擇python3,,然後你就可以用python3編譯了,ctrl+B 是快捷鍵

Python相關