- 执行其他程序
execfile()函数
//导入模块不是很好,导致最高级代码运行
f=open(filename,'r')
exec f
f.close()
用execfile函数就是
execfile(filename)
- 执行其他非python程序
主要函数有:
system(cmd)
fork()
execl(file,arg0,arg1)
execv(file,arglist)
execle(file,arglist,env) ,和execl相同,提供了环境变量字典env
startfile(path)
popen(cmd,mode=’r’,buffering=-1) ,这个函数相当于提供了一个文件句柄,可以把cmd执行的命令用文件的方式来访问
- 正则表达式
compile()函数,返回的是regex对象,这里说道用预编译过的对象比直接执行字符串那种性能有提升
match(pattern,string,flags=0),返回匹配到的对象
search(pattern,string,flags=0)
findall(pattern,string[,flags])
split(pattern,string,max=0)
sub(pattern,repl,string,max=0),替换函数,把字符串string中所有匹配正则表达式pattern的地方替换成字符串repl,如果max没给出,所有匹配到的都替换
group(num=0),返回匹配到的对象,或者特定的元组
gourps(),返回匹配的所有元组
subn(),和sub()一样,不过最后返回的结果中给出替换的次数,以元组的结果呈现。