[Tutor] Multi-line statements with comments
Gregor Lingl
glingl@aon.at
Sat, 29 Dec 2001 15:53:15 +0100
...
>
> def removeComments(s):
> return comment_re.sub('\n', s)
> ###
>
...
>
> However, there's one big deficiency in the regular expression as it
> stands: what happens if we give it soething like this?
>
> ###
> s = removeComments("hello # why doesn't this comment disappear?")
> print s
> ###
>
>
> So there's definitely room to improve this.
>
Would you consider this to be an appropriate
proposition:
def removeComments(s):
return comment_re.sub('\n', s+'\n')[:-1]
?
Gregor