一、单个函数
1、str_to_int()函数:将input()输入的字符串转化为int
def str_to_int(str):
'''
Convert string to int
param:: "str": string
return:: "x":int
'''
str1 = re.sub(' ','',str)
print(str1)
assert str1.isdigit(),"Please input the current index!"
x = []
slen = len(str)
i = 0
s = 0
f = 0
while i
2 、pdf_file_list()函数:pdf文件搜索函数
def pdf_file_list(fpath):
"""
Get paths of all pdf files
param:: "fpath":The root path
return:: "pdf_paths":The paths of all pdf files
"""
assert os.path.exists(fpath), 'The folder path does not exist'
pdf_paths = list()
for root, dirs, files in os.walk(fpath):
for file in files:
if file.endswith('.pdf'):
pdf_paths.append(os.path.join(root, file))
return pdf_paths
3、pdf_merge()函数:pdf拼接函数
def pdf_merge(fpath):
"""
Merge the pdf files
param:: "fpath":The paths of pdf
return:: None
"""
fmerge = PyPDF2.PdfFileMerger()
for pdf in fpath:
fmerge.append(pdf)
fmerge.write('result.pdf')
二、全部代码
from importlib.resources import path
from operator import length_hint
import re
import PyPDF2
import os
from numpy import append
from requests import patch
def pdf_file_list(fpath):
"""
Get paths of all pdf files
param:: "fpath":The root path
return:: "pdf_paths":The paths of all pdf files
"""
assert os.path.exists(fpath), 'The folder path does not exist'
pdf_paths = list()
for root, dirs, files in os.walk(fpath):
for file in files:
if file.endswith('.pdf'):
pdf_paths.append(os.path.join(root, file))
return pdf_paths
def pdf_merge(fpath):
"""
Merge the pdf files
param:: "fpath":The paths of pdf
return:: None
"""
fmerge = PyPDF2.PdfFileMerger()
for pdf in fpath:
fmerge.append(pdf)
fmerge.write('result.pdf')
def str_to_int(str):
'''
Convert string to int
param:: "str": string
return:: "x":int
'''
str1 = re.sub(' ','',str)
print(str1)
assert str1.isdigit(),"Please input the current index!"
x = []
slen = len(str)
i = 0
s = 0
f = 0
while i