[Tutor] binary file query

Prasad, Ramit ramit.prasad at jpmorgan.com
Wed Nov 16 17:44:37 CET 2011


>If we are opening a binary file in python then do we have to use "Import struct" and do "struct.unpack" to work on the data from that binary file?
>Will we be able to process the file as text file without using struct?

You should open the file with the 'rb' parameter and then read from it as you need to. 

with open( 'filename.ext', 'rb' ) as f: # python 2.6+ syntax
    f.read( [size] ) # OR
    f.readline( [size] )

http://docs.python.org/tutorial/inputoutput.html
Start from section 7.2

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  


More information about the Tutor mailing list