0

I am trying to delete comments from a file, the comments start with "#" symbol. I am able to remove comments that starts the line with '#' but there are some comments in the file that are starting in between the line. Is there any method to remove comments like that.?

Here is the sample code.

# modified code
begin
 stuff
 stuff
end # ended module

I want to delete the text followed by # in line 5.

2
  • 1
    What did you try to solve this problem? Jun 26, 2017 at 19:48
  • Loop over each line and split('#')[0] . Assuming you don't have any # inside strings of course.
    – t.m.adam
    Jun 26, 2017 at 20:07

0

Browse other questions tagged or ask your own question.