Python 食谱

来源:互联网 发布:淘宝网皮衣 编辑:程序博客网 时间:2024/04/18 22:56

1) Check whether python is 64bit or 32bit?
import sys
is_64bits = sys.maxsize > 2**32

2) Install python into a specific path?

python setup.py install --prefix=/path/to/install/ --exec-prefix=/path/to/execute/

3) Resource ‘taggers/maxent_treebank_pos_tagger/english.pickle’ not
found. (解决nltk.pos_tags)

When you type nltk.download() in Python, an NLTK Downloader interface gets displayed automatically.Click on Models and choose maxent_treebank_pos_. It gets installed automatically.

4) 随机生成固定长度的大写字母和数字的混合

import string, random''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(n))

小写字母则:

''.join(random.choice(string.lowercase + string.digits) for _ in range(n))

5) 当import string,遇到AttributeError: 'module' object has no attribute 'lowercase'错误时。

Turn 'string.lowercase' to 'string.ascii_lowercase'

6) 怎样从command命令里面启动sublime 2 for MAC:

ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime
0 0