[Tutor] regex and parsing through a semi-csv file

Prasad, Ramit ramit.prasad at jpmorgan.com
Tue Oct 25 17:02:59 CEST 2011


>f = open(args.fname, 'r')
>lines = f.readlines()
>f.close()

If you are using Python 2.6+ you can use a context manager to automatically close the file. That way you never have to worry about closing any files!

with open(args.fname, 'r') as f:
    lines = f.readlines()


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