正则表达式简单的使用

 

 1 import re
 2 origin = "3-5*6+(20-3-4*((30/5-5)*6)+(5*6-7*(20-2))-(8*8))+195"
 3 def f(str):
 4     ss = eval(str)
 5     return ss
 6 while True:
 7     res = re.split("\(([^()]+)\)", origin, 1)
 8     if len(res) == 3:
 9         befor, mid, after = res
10         ret = f(mid)
11         print(type(befor), type(mid), type(after))
12         origin = str(befor) + str(ret) + str(after)
13         print(origin,type(origin))
14     else:
15         rr = f(origin)
16         print(int(rr))
17         break

     OS模块常用

os.stat('path/filename') 获取文件/目录信息
os.path.dirname(path)返回path的目录
os.path.exists(path)如果path存在,返回True,如果不存在返回 False
os.path.join(path1,path2,...)将多个路径组合后返回,第一个绝对路径之前参数将被忽略