Solved

read data from input file stream

Posted on 2013-12-30
1
479 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
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 lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now