Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

read data from input file stream

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
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 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…

829 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