Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python read hex file

(While Running Multiple Containers)
Setting "stdin_open:true" to your react instance

    react:
            stdin_open: true //NOTE:
            build: dockerreact
            ports: - "3000:3000"
            
#Change to: open(filename).read()

with open('/path/to/some/file', 'r') as fp:
    hex_list = ["{:02x}".format(ord(c)) for c in fp.read()]
Or, if you do not want to keep the whole list in memory at once for large files.

hex_list = ("{:02x}".format(ord(c)) for c in fp.read())
and to get the values, keep calling

next(hex_list)
to get all the remaining values from the generator

list(hex_list)
 
PREVIOUS NEXT
Tagged: #python #read #hex #file
ADD COMMENT
Topic
Name
2+7 =