Answers for "python read file and keep ends"

2

python read file and keep ends

# 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
Posted by: Guest on December-01-2021

Code answers related to "python read file and keep ends"

Python Answers by Framework

Browse Popular Code Answers by Language