python入门级问题
照葫芦画瓢,写了几行,有个问题弄不明白:
1#include <iostream>2 int main()3 {4 cout<<"22"<<endl;//335 return 0;6 }
#!pythonimport rep=re.compile(r"^\d+")f=open("x.cpp",'r')o=open("c.cpp",'w')for l in f: m=p.match(l) oldstr=m.group() o.write(l.replace(oldstr,l))f.close()o.close()
1#include <iostream>#include <iostream>2 int main() int main()3 { {4 cout<<"22"<<endl;//33 cout<<"22"<<endl;//335 return 0; return 0;6 } }
import redef main(): f=open("x.cpp","r") o=open("c.cpp","w") for l in f: m=re.search("\D+",l) o.write(l.replace(l,m.group()))if __name__=='__main__': main()