【发布时间】:2020-02-11 13:11:51
【问题描述】:
我使用以下代码从 docx 获取字符串。或pptx。 (由于 textract 不能正确使用非 acsii 符号,我使用here 描述的解决方案):
import textract as txt
text = txt.process("D:\Corpus\Exposee.pptx")
text = text.decode("utf8")
然后我调用text 得到如下字符串:
'Syntaktische Besonderheiten \n\ndes Maschinellen Verstehens \n\nder Deutschen Sprache \n\nin der Multilingualen Perspektive\n\nMarvin Teller\n\nForschungsfrage\n\nW\n\nelche\n\n \n\nEigenschaften\n\n \n\n\n\n\tder \n\nsyntaktischen\n\n \n\nStruktur\n\n der \n\n
(缩短)
我想要没有\n 和\t 等标签的字符串,该怎么做?
对于可能的重复/幼稚,请提前道歉
【问题讨论】:
-
你称它为基础版本,\n 允许段落,尝试使用 print(text) 然后你会明白我的意思
-
但如果你确实想删除它,请执行 text = text.remove()
-
@TommyLawrence 感谢您的建议!但是,在将 'remove' 应用于字符串(文本)时,我得到“AttributeError:'str' object has no attribute 'remove'”
-
好吧,对不起,是替换,做 text = text.replace("\n", "")
标签: python tags powerpoint text-extraction