服务器上跑程序,除了基础python外,连re library都是不能有的,于是只能搞字符操作完成。记一笔,以备日后还要跑上去。
###为了把某md文件的段落结构重组,比如原来的##变为###, ###变为####。
result_file = open("result_file.md","w")
with open('formalizing_rq.md', 'r') as f:
for line in f:
the_list_line=[]
the_list_line = line.split(None, 1) # add only first word
if the_list_line != []:
the_first_word = the_list_line[0]
first_word_list = list(the_first_word) # convert string to list
symbol_of_first_word = list(set(first_word_list)) #simplify the items in the first string
str_symbol = ''.join(str(e) for e in symbol_of_first_word)
if str_symbol == '#':
the_new_first_word = the_first_word + "#"
the_list_line[0] = the_new_first_word
result_file.write(' '.join(the_list_line))
the_list_line="\n"
else:
result_file.write(line)
the_list_line="\n"
else:
result_file.write(line)
result_file.close()