how to remove c++ comments from a cpp file?

Frank Potter could.net at gmail.com
Fri Jan 26 09:46:37 CET 2007


I only want to remove the comments which begin with "//".
I did like this, but it doesn't work.

r=re.compile(ur"//[^\r\n]+$", re.UNICODE|re.VERBOSE)
f=file.open("mycpp.cpp","r")
f=unicode(f,"utf8")
r.sub(ur"",f)

Will somebody show me the right way?
Thanks~~




More information about the Python-list mailing list