Skip to content

Instantly share code, notes, and snippets.

@zgrge
Created April 6, 2018 17:50
Show Gist options
  • Save zgrge/57db5d7c2b91c444cf42681f9926a8f8 to your computer and use it in GitHub Desktop.
Save zgrge/57db5d7c2b91c444cf42681f9926a8f8 to your computer and use it in GitHub Desktop.
record = b'raymond \x32\x12\x08\x01\x08\x0c\x07\x1b\r\x03\x04'
name, serialnum, school, gradelevel, Y, m, d, H, M, S = struct.unpack('<10sHHb6b', record)
from collections import namedtuple
#Can i instantly get Datetime object from unpack below?
Student = namedtuple('Student', 'name serialnum school gradelevel Y m d H M S')
Student._make(struct.unpack('<10sHHb6b', record))
dt = datetime(Y, m, d, H, M, S)
print(dt.strftime('%Y-%m-%d %H:%M:%S'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment