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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started