控制台打印乱码:
print '你好,世界!'.decode('utf-8')
url = 'http://{0}:{1}/{2}'.format('0.0.0.0', 2375, 'xxx')
url = 'http://{ip}:{port}/{uri}'.format(ip='0.0.0.0', port=2375, uri='xxx')
url = 'http://%s:%d/%s' % ('0.0.0.0', 2375, 'xxx')
whl
包下载pip install *.whl
或者修改.whl
文件为.zip
文件,解压缩文件的Python文件夹
复制到--python
安装目录下的Lib
--目录下假如
sys.path
不对,则使用Python终端sys.path = [...]
重新设置即可. 默认环境配置如下:
root@node-40:~# python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7']
>>>
# /etc/profile
export PYTHONPATH=/usr/lib/python2.7:/usr/lib/python2.7/plat-x86_64-linux-gnu:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages/PILcompat:/usr/lib/python2.7/dist-packages/gtk-2.0:/usr/lib/pymodules/python2.7
export PATH=$PATH:$PYTHONPATH
Python2.7
与Python3.x
共同使用$ py -2
$ py -3
$ py -2 -m pip xxx
$ pip3 xxx
settings
settings
--> code compatibility inspection
下载服务器:
Python2.x
$ python -m SimpleHttpServer
默认端口8000$ py -2 -m SimpleHTTPServer
默认端口8000$ py -2 -m SimpleHTTPServer 9090
指定端口9090
import SimpleHTTPServer
SimpleHTTPServer.test()
$ python -m http.server
$ py -3 -m http.server
Json格式化:$ curl http://localhost:8080/get | python -m json.tool
执行Python代码:$ python -c "print 'hello world!'"
解压zip包:
$ python -m zipfile -c tom.zip tom.txt
$ python -m zipfile -e tom.zip .
$ python -m zipfile -l tom.zip
文件处理:
import shutil
shutil.copy('C:\Users\Administrator\Desktop\ctools2.rar','q.rar')
maptplotlib
, malb
, numpy
, tesseract
bs4
, xpath