【发布时间】:2022-01-25 18:58:12
【问题描述】:
我从一个 pdf 文件中提取所有文本作为字符串,并通过删除所有双空格、换行符(两个或更多)、空格(如果两个或更多)以及每个点 ( .)。 现在在我的列表中,如果列表的值仅包含特殊字符,则应排除该值。
pdfFileObj = open('Python String.pdf', 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
pageObj = pdfReader.getPage(0)
text=pageObj.extractText()
z =re.split("\n+|[.]|\s{2,}",text)
while("" in z) :
z.remove("")
print(z)
我的输出是
['split()', 'method in Python split a string into a list of strings after breaking the', 'given string by the specified separator', 'Syntax', ':', 'str', 'split(separator, maxsplit)', 'Parameters', ':', 'separator', ':', 'This is a delimiter', ' The string splits at this specified separator', ' If is', 'no', 't provided then any white space is a separator', 'maxsplit', ':', 'It is a number, which tells us to split the string into maximum of provi', 'ded number of times', ' If it is not provided then the default is', '-', '1 that means there', 'is no limit', 'Returns', ':', 'Returns a list of s', 'trings after breaking the given string by the specifie', 'd separator']
这里有一些只包含特殊字符的值,我想删除它们。谢谢
【问题讨论】: