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

Frank Potter could.net at gmail.com
Fri Jan 26 03:46:37 EST 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