re.sub返回一个字符串,因此将代码更改为以下内容将得到结果:
def removeComments(string): string = re.sub(re.compile("",re.DOTALL ) ,"" ,string) # remove all occurrences streamed comments () from string string = re.sub(re.compile("//.*?n" ) ,"" ,string) # remove all occurrence single-line comments (//COMMENTn ) from string return string


