Solved

read data from input file stream

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

743 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

12 Experts available now in Live!

Get 1:1 Help Now