In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "Python splitter how to use", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Python splitter how to use" it!
# split the txt novel into multiple HTML files
# @ author: GreatGhoul
# @ email: greatghoul@gmail.com
# @ blog: http://greatghoul.javaeye.com
Import re
Import os
# regex for the section title
# sec_re = re.compile (r'. + Volume\ sroom.+\ s+ Chapter.
# txt book's path.
Source_path ='f:\\ mercenary .txt'
Path_pieces = os.path.split (source_path)
Novel_title = re.sub (r'(\.. * $) | ($)','', path_pieces [1])
Target_path ='% s% sroomhtml'% (path_pieces [0], novel_title)
Section_re = re.compile (r'^\ s* volume. + volume\ sroom.resume')
Section_head ='
% s
% s go to footer''
# escape xml/html
Def escape_xml (code):
Text = code
Text = re.sub (rushing,'>', text)
Text = re.sub (ringing girls,'&', text)
Text = re.sub (r'\ tasking,'', text)
Text = re.sub (r'\ s,'', text)
Return text
# entry of the script
Def main ():
# create the output folder
If not os.path.exists (target_path):
Os.mkdir (target_path)
# open the source file
Input = open (source_path,'r')
Sec_count = 0
Sec_cache = []
Idx_cache = []
Output = open ('% s\\% d.html'% (target_path, sec_count),'w')
Preface_title ='% s foreword'% novel_title
Output.writelines ([section_head% (preface_title)
Preface_title)])
Idx_cache.append ('% s'
% (sec_count, novel_title))
For line in input:
# is a chapter's title?
If line.strip () ='':
Pass
Elif re.match (section_re, line):
Line = re.sub (r'\ s subscription,'', line)
Print 'converting% s..'% line
# write the section footer
Sec_cache.append ('
')
If sec_count = = 0:
Sec_cache.append ('directory |')
Sec_cache.append ('next article |'
% (sec_count + 1))
Else:
Sec_cache.append ('previous article |'
% (sec_count-1))
Sec_cache.append ('directory |')
Sec_cache.append ('next article |'
% (sec_count + 1))
Sec_cache.append ('go back to the top of the page
')
Sec_cache.append ('')
Output.writelines (sec_cache)
Output.flush ()
Output.close ()
Sec_cache = []
Sec_count + = 1
# create a new section
Output = open ('% s\\% d.html'% (target_path, sec_count),'w')
Output.writelines ([section_head% (line, line)])
Idx_cache.append ('% s'
% (sec_count, line))
Else:
Sec_cache.append ('% s
'
% escape_xml (line))
# write rest lines
Sec_cache.append ('next article |'
% (sec_count-1))
Sec_cache.append ('directory |')
Sec_cache.append ('go back to the top of the page
')
Output.writelines (sec_cache)
Output.flush ()
Output.close ()
Sec_cache = []
# write the menu
Output = open ('% s\\ index.html'% (target_path),'w')
Menu_head ='% s directory'% novel_title
Output.writelines ([section_head% (menu_head, menu_head)
''])
Output.writelines (idx_cache)
Output.writelines (['])
Output.flush ()
Output.close ()
Inx_cache = []
Print 'completed. D chapter (s) in total.' sec_count
If _ _ name__ = ='_ _ main__':
Main ()
Thank you for your reading, the above is the content of "how to use the Python splitter", after the study of this article, I believe you have a deeper understanding of how to use the Python splitter, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.