Skip to content

Instantly share code, notes, and snippets.

@ronnyworm
Created June 1, 2022 06:50
Show Gist options
  • Save ronnyworm/aa47fa30ca23504dbbab1e463351887d to your computer and use it in GitHub Desktop.
Save ronnyworm/aa47fa30ca23504dbbab1e463351887d to your computer and use it in GitHub Desktop.
# Is the file ending with a newline? Python Function
def ending_with_newline(filename):
last_byte = None
with open(filename, "rb") as f:
while True:
byte = f.read(1)
if not byte:
break
last_byte = byte
return last_byte == b'\n'
# I couldn't find an example on the internet, that's why I'm sharing
# enjoy!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment