Question: Python help here's part of my python code to read a java file and strip the comments out of the file, and write the java

Python help

here's part of my python code to read a java file and strip the comments out of the file, and write the java code which has no comment to a new file.

(e.g. the line of java code changed from

system.out.println("Hello world"); // comment

to

system.out.println("Hello world");

)

How do I modify my code to scan that if the char after the char "/" is another "/", then break the inner for-loop and read the next line? So that I ignored the content after "//" in a line and do not write them into a new file.

here's my python code:

import sys

output = open("someDocument", "w")

with open("anotherDocument.java", 'r+') as the_file:

for line in the_file:

for ch in line:

if (ch == "/"):

if (ch == "/"):

break

else:

output.write(ch)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!