The code generated by PowerDesigner has a lot of comments, and it looks ugly, what should we do, let us use Python to easily solve this problem?

as the picture shows:
Insert picture description here

Step 1: Write Python code

code show as below:

import os
import re
 

lines = (i for i in open('F:\\2\\test.txt', 'r') if '/' not in i )
f = open('F:\\2\\test_new.txt', 'w', encoding="utf-8")
f.writelines(lines)
f.close()
os.rename('test.txt', 'test1.bak')
os.rename('test_new.txt', 'test.txt')
os.remove('test1.bak')

Step 2: Create a new file:

As can be seen from the above code, our open file path is F:\2\test.txt, so
we need to create a new file. as the picture shows:

Insert picture description here

Step 3: Copy the generated Java code to the test.txt file

as the picture shows:
Insert picture description here

Step 4: Run the Python file

Remember to close the text.txt file that we posted the code just now when running, otherwise it won't work.
As shown in the figure:
Insert picture description here
After running, there is no error:
Insert picture description here
Check the test.txt file:
Insert picture description here
the effect we want has been achieved, is it more attractive?

Guess you like

Origin blog.csdn.net/qq_45137584/article/details/111017937