Skip to content

Instantly share code, notes, and snippets.

View drsxr's full-sized avatar
💭
Doing heavy math

Stephen B drsxr

💭
Doing heavy math
View GitHub Profile
@drsxr
drsxr / read_last_line_of_file.py
Created July 19, 2022 22:28
Get last line of file (csv) without reading the entire file into memory
#This works. Yields the last line of the file as a string without reading the entire file into memory.
#Use a parsing function to separate returned data by commas to select the desired element.
import os
def get_last_line_records_of_file(identifier_data):
filepath = linux_path+"/"+identifier_data+".csv"
try:
with open(filepath,'rb') as f:
f.seek(-1,os.SEEK_END)