Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import array
- import binascii
- import tempfile
- a = array.array('i', xrange(5))
- print 'A1:', a
- # Write the array of numbers to a temp file
- output = tempfile.NamedTemporyFile()
- a.tofile(output.file) # must pass an actual file
- output.flush()
- # Read the raw data
- with open(output.name, 'rb') as input:
- raw_data = input.read()
- print 'Raw Contents:', binascii.hexlify(raw_data)
- # Read the data into an array
- input.seek(0)
- a2 = array.array('i')
- a2.fromfile(input, len(a))
- print 'A2:', a2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement