Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

What are the classifications of Bank?

Answered: 1 week ago