[CentralOH] 2013-04-11 道場

Kurtis Mullins kurtis.mullins at gmail.com
Fri Apr 12 22:01:58 CEST 2013

On Fri, Apr 12, 2013 at 10:31 AM, Eric Floehr <eric at intellovations.com>wrote:

> And if you are using Python 2.5 or higher, this is "best", as it closes
> the file always, even on an exception:
> with open('foo', 'rU') as f:
>     for line in f:
>         # Do whatever with line or pass

That's actually what I use as well; however, I still have to check for
blank lines. I assumed that's what jep was alluding to.

For example (out of a script I recently wrote):

with open(negation_lexicon_file_name, 'rb') as negation_file:
    for line in negation_file:
        phrase = line.strip().lower()
        if phrase:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20130412/99f48715/attachment.html>

More information about the CentralOH mailing list