Last active
June 5, 2016 14:43
-
-
Save xgfs/b283b6efc6cf0efd1bdc to your computer and use it in GitHub Desktop.
How do i read that binary file
This file contains 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
from struct import unpack | |
fname = r'D:\vk_1015\group_data_inv.bin' | |
buffer_size = 1024 | |
last_node = 1 | |
user_subs = {1: []} | |
stop = False | |
with open(fname, 'rb') as f: | |
while True: | |
bytes = f.read(4*buffer_size) | |
if len(bytes) == 0: | |
break | |
buffer_values = unpack('i'*(len(bytes)/4), bytes) | |
#print buffer_values | |
#break | |
for idx, value in enumerate(buffer_values): | |
if value <= 0: | |
last_node = -value | |
if last_node > max(user_subs.keys()): | |
stop = True | |
break | |
else: | |
if last_node in user_subs: | |
user_subs[last_node].append(value) | |
if stop: | |
break | |
del(bytes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment