Solved

read data from input file stream

Posted on 2013-12-30
1
481 Views
Last Modified: 2014-01-04
Hi guys,

I have the following method defined in python :

def amrPayload2Storage_OctetAlignedMode(payload):
    try:
        # assume no interleaving, CRCs or bit re-ordering
        bitlen = [95,103,118,134,148,159,204,244,39]
        amr = BitArray(bytes=payload)
        cmr = amr[0:4]
        res = amr[4:8]
        assert res.uint==0,'amr[4:8] must be zero'
        f = amr[8]
        mode = amr[9:13]
        qual = amr[13:14]
        pad = amr[14:16]
        if mode.uint >=0 and mode.uint <= 8:
            assert amr.len >= 16+bitlen[mode.uint]
            voice = amr[16:16+bitlen[mode.uint]]
            storage = BitArray(bin='0')
            storage.append(mode)
            storage.append(qual)
            storage.append('0b00') # padding
            assert storage.len==8,"check length of storage header is one byte"
            storage.append(voice)
            return storage.tobytes()
    except:
	import pdb
#    pdb.pm() # or pdb.post_mortem()
	pdb.set_trace()
    return ''

Open in new window



I want to read the data from an input file and pass it to the function, I need help on how to do that?

Thanks
0
Comment
Question by:bachra04
1 Comment
 
LVL 28

Accepted Solution

by:
pepr earned 500 total points
ID: 39747919
with open('thefile.data', 'rb') as f:
    payload = f.read()

Open in new window


Now you have your payload ready.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question