Home > other >  How to remove the empty line of a text, digital sign
How to remove the empty line of a text, digital sign

Time:10-12

Topic request is: please write a program to extract all of the original content in "the analects" document, save the output to "of" the analects of Confucius - extract version. TXT file, the output file format requirements: removes white Spaces at the part of each line the first original articles and digital sign, such as "1.11" end of each line with no Spaces, no empty lines, reference format is as follows (the original brackets and internal number is corresponding to the source file comment tags) :????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

Confucius said: (1) "learning (2) (3) of reviewing at times and not also said (4)? To have friends (5) come from afar, not as well joy (6)? People do not know (7), while not best (8), not as well a gentleman (9)?"

The son (1) yue: "a man is filial piety (2), and make good (3), bright (4) yi; Bad mistake, and the good of the crisis, not have also (5), the gentleman wu Ben (6), the state and the tao gave birth to (7), filial piety, also its character of this and (8)?"

Confucius said: "fresh knowledge (1), (2) ren yi

Reference answer: fi=open (" analects of Confucius - online. TXT ", "r", encoding="utf-8")
Fo=open (" the analects of Confucius - extract version. TXT ", "w")
Wflag=False # write tag
For the line in fi:
If "[" in line: # meet [, that has come to a new area, write tag no gainsaying
Wflag=False
If "[sic]" in line: # meet [sic], setting write flag to True
Wflag=True
The continue
If wflag==True: # according to write tag the current row content into a new file
For I in range (0, 25) :
For j in range (0, 25) :
The line=line. Replace (" {}, {} ". The format (I, j), "* *")
For I in range (0, 10) :
The line=line. Replace (" * {} ". The format (I), "")
For I in range (0, 10) :
The line=line. Replace (" {} "*". The format (I), "")
The line=line. Replace (" * ", "")
Xsl-fo. Write (line)
Fi. Close ()
Xsl-fo. Close ()


Consult a great god, and the contents of the code of four for loop what's the meaning of
Especially the line=line. Replace (" * {} ". The format (I), "") here really don't understand (I was ashamed

CodePudding user response:

Use positive side not soon? !!!!!!!!!

CodePudding user response:

Ha ha, this idea of fun, but also a solution,

Principle of the idea is to replace the 1.11, the results
1.11 the first cycle, convert into * * 1

So you also need a second cycle have replaced * 1 is empty,

11.1 the first loop, also be replaced with 1 * *
Also need the third cycle, have replaced 1 * is empty

Finally, have replaced all the * is empty


This code is written after the author said: programming!

This live according to the above said method, regular is king,

CodePudding user response:

Give two great god kneel...
Thank you thank you
  • Related