最近在看python标准库这本书,第一感觉非常厚,第二感觉,里面有很多原来不知道的东西,现在记下来跟大家分享一下. string类是python中最常用的文本处理工具,在python的标准库中,有大量的工具,可以帮助我们完成高级文本处理. capwords()是将一个字符串中的所有单词的首字母大写. import string s = 'The quick brown fox jumped over the lazy dog.' print s print string.capw…
JUNE 28TH, 2014Tweet This article describes how Python string interning works in CPython 2.7.7. A few days ago, I had to explain to a colleague what the built-in function intern does. I gave him the following example: >>> s1 = 'foo!' >>>…
http://www.laurentluce.com/posts/python-string-objects-implementation/ Python string objects implementation June 19, 2011 This article describes how string objects are managed by Python internally and how string search is done. PyStringObject structu…
#Python绘制 文本进度条,带刷新.时间暂缓的 #文本进度条 import time as T st=T.perf_counter() print('-'*6,'执行开始','-'*6) maxx=11 #要大1 for i in range(maxx): s1='*'*i s2='->' s3='.'*(maxx-i-1) T.sleep(0.5) #假装有延时 dur=T.perf_counter()-st print("\r%3d%%[%s%s%s] %.2fs"%(i…
python根据文本生成词云图 效果 代码 from wordcloud import WordCloud import codecs import jieba #import jieba.analyse as analyse from scipy.misc import imread import os from os import path import matplotlib.pyplot as plt from PIL import Image, ImageDraw, ImageFont…
In [8]: import string In [9]: dir(string) In [10]: string.ascii_letters Out[10]: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' In [11]: string.ascii_lowercase Out[11]: 'abcdefghijklmnopqrstuvwxyz' In [12]: string.ascii_uppercase Out[12]: 'AB…
In [8]: import string In [9]: dir(string) In [10]: string.ascii_letters Out[10]: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' In [11]: string.ascii_lowercase Out[11]: 'abcdefghijklmnopqrstuvwxyz' In [12]: string.ascii_uppercase Out[12]: 'AB…