python 字符串与正则表达式
来源:互联网 发布:汇丰软件 劝退 编辑:程序博客网 时间:2024/05/28 16:14
s.find(sub,start=0,end=sys.maxint) if it haven't find the substring ,return -1
Bool s.isdigit(), if len(s)==0 then return False
Bool s.isalnum()s.isalpha(),s.islower(),s.isspace(),s.isupper()
s.join(seq)
s.split()
maketrans(str1,str2)将str1中的字母翻译成str2中,一一对应,translate(table,deletechars='')其中的table就可以用maketrans产生的,这个函数将把deletechars的字符删掉,然后按照table的规则进行转换。
for instance
import string
intoas=string.maketrans('eiou','aaaa')
print 'somestring.'.translate(intoas)
print 'somestring.'.translate(intoas,'s')
精度转换
而%f %F float
%g %G是在exp>=4 orexp<=精度时候,与e或E一样,否则和F or f一样
import codecs
#open(filename,mode='rb',encoding=None,errors='strict',buffering=1)
fileout = codecs.open('uni.txt','w','latin-1','replace')
fileout.write(u'gauss')将unicde字符串写入到文件uni.txt中,并让字符串在文件中被隐式编码为latin-1,同时,在对任何不能以latin-1编码的字符,将其替换为‘?’,如果errors是ignore,转换工作将跳过错误,还有是xmlcharrefreplace,
buffering :1写入缓存中,通过close()存入硬盘,而buffering=0 将直接对硬盘操作
EncodedFile(file,datacodec,filecodec=None,errors='strict')
包装类文件对象file,返回一个类文件对象ef,在向ef写入一个str时候,ef将首先使用datacodec解码,然后用filecodec编码在写入file中,从ef读取一个字符串时候,就相反,
例如,用latin-1编码的字符串写入到sys.stdout,并且输出编码方式为utf8的字符串,
import sys,codecs
sys.stdout = codecs.EnocdedFile(sys.stdout,'latin-1','utf-8')
- python 字符串与正则表达式
- python字符串与正则表达式
- Python 第十四周 字符串与正则表达式
- python之路-------字符串与正则表达式
- python 字符串匹配与正则表达式
- 字符串与正则表达式
- 字符串与正则表达式
- 字符串与正则表达式
- 字符串与正则表达式
- 正则表达式与python
- Python与正则表达式
- 正则表达式与Python
- python与正则表达式
- python 学习记录(10)-字符串与正则表达式
- python开发技术详解---第六章:字符串与正则表达式
- Python 正则表达式验证字符串
- python正则表达式 分割字符串
- 13 - 字符串与正则表达式
- python 中文编码(unicode,gbk,utf8,ordinary string)
- string文件中的内容动态生成
- python 类
- python 多线程
- VS2008利用宏添加注释模板
- python 字符串与正则表达式
- python email模块学习笔记
- python Tkinter图形用户界面组件(Entry,Button)一
- python Tkinter图形用户界面组件(布局管理器) 二
- MongoDB学习笔记(五) MongoDB文件存取操作
- python Tkinter图形用户界面组件(布局管理器) 三
- 装饰器思想 由python联想到javascript
- python Pyro(python中的RMI)学习笔记一
- python Pyro(python中的RMI)学习笔记