【问题标题】:Transform Word Document data into showing the "new line" separator within the text将 Word 文档数据转换为在文本中显示“新行”分隔符
【发布时间】:2021-12-11 17:30:29
【问题描述】:

所以我正在尝试将标准 Word 文档转换为 csv 格式,其中在文本本身中包含“\n”换行符或“\n”。我将使用这些数据来微调我正在研究的自然语言模型。

例如,

Hey there,

My name is Jim and I'm excited to begin working for Microsoft. I believe my job history fits perfectly within the Microsoft Culture.

Thanks!
Jim

会变成

您好,\n我叫 Jim,很高兴能开始为 Microsoft 工作。我相信我的工作经历完全符合微软文化。 \n谢谢! \n吉姆

我尝试使用 Notepad++ 来显示换行符,它确实做到了,但它的格式很奇怪,实际上并没有显示文本,而只是直观地显示了换行符的位置。

【问题讨论】:

    标签: python csv text ms-word


    【解决方案1】:

    使用repr()显示字符串的字符串表示。

    例如

    text = """Hey there,
    
    My name is Jim and I'm excited to begin working for Microsoft. I believe my job history fits perfectly within the Microsoft Culture.
    
    Thanks!
    Jim"""
    
    new_text = repr(text)
    

    输出:

    print(new_text)
    > "Hey there,\n\nMy name is Jim and I'm excited to begin working for Microsoft. I believe my job history fits perfectly within the Microsoft Culture.\n\nThanks!\nJim"
    

    【讨论】:

    • 天哪,太感谢你了,不知道python有这个lol
    猜你喜欢
    • 2012-03-07
    • 1970-01-01
    • 2015-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多