Some comics are sometimes downloaded from the Internet, usually in image format, JPG or PNG. The effect of these pictures online preview is good, but once downloaded to the local, the browser is more troublesome:
Need to flip the arrow keys up and down
By default, the picture is completely displayed in the screen, causing the picture to be small and unclear.
Based on this consideration, write the following Python script, you can read the comic folder images, renamed to a regular picture name to generate the corresponding HTML file, so that you can browse through the HTML image, and browse the effect is much better.
#!\usr\bin\env python#-*-coding:utf-8-*-import os# Gets the current path, PATH = OS.GETCWD () #获取当前路径下所有文件fileList = Os.listdir (path) i= 1for file in Filelist:ext = os.path.splitext (file) [1] #读取后缀为 jpg files and rename them if Ext.strip () = = '. jpg ': Os.rename (file,str (i) +r '. jpg ') i=i+1# create an HTML file locally f=open (R ' index.html ', ' w+ ') for I in Range (1,i): FileName = str (i) +r '. jpg ' image=r ' < IMG src= "' + fileName + R '"/> ' f.write (image) F.close ()
python-Comics Auxiliary Script-rename a picture inside a folder to generate HTML