Created
June 1, 2022 06:50
-
-
Save ronnyworm/aa47fa30ca23504dbbab1e463351887d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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