(I appreciate this sounds like a duplicate, but I've tried multiple things with no luck)
I'm trying to output the entire contents of multiple .pkt files, containing binary data, as a series of hexadecimal lists: (Adapted from How to open every file in a folder?)
import glob
path = 'filepath' for filename in glob.glob(os.path.join(path, '*.pkt')):
with open(os.path.join(os.getcwd(), filename), 'rb') as f:
pair_hex = ["{:02x}".format(c) for c in f.read()]
print(pair_hex)
#output
['09', '04', '04', '04', '04', '04', '04', '04', '04', '0b', '09']
['09', '04', 'bb']
['09', 'bb']
['bb']
['09', '04', '0b', '09']
The output makes sense, because i'm looping through the files, but what I need is:
[['09', '04', '04', '04', '04', '04', '04', '04', '04', '0b', '09'],['09', '04', 'bb'],['09', 'bb'],['bb'],['09', '04', '0b', '09']]
So I can manipulate all the data.
I have tried to apply append(), "".join(), map() and itertools (How to merge multiple lists into one list in python?), but nothing changes the output. I realise this is probably quite simple, but I'm quite new to Python so not sure best to proceed.
Thanks in advance!