📜  python如何保留换行符 - Python代码示例

📅  最后修改于: 2022-03-11 14:47:21.999000             🧑  作者: Mango

代码示例1
# Basic syntax:
with open('your_file', 'r', newline='') as file:
    data = file.read().splitlines(keepends=True)

# Where:
#    - newline='' causes line endings to be returned to the caller untranslated
#    - keepends=True causes newline characters to be retained after splitting

# See additional Python documentation about this here:
https://docs.python.org/release/3.2/library/functions.html#open
https://docs.python.org/3/library/stdtypes.html#str.splitlines