trampgeek/pycode — pull request #3 by lfairy (2012-09-03 02:14:54+00:00)
Title: Improve PycodeFile compatibility

I just fixed up the `PycodeFile` class to more closely match the [standard interface][file-objects], after getting repeated errors on the pylearn site :(

[file-objects]: http://docs.python.org/library/stdtypes.html#file-objects

The patch adds the following:

* The mode argument on the `open` function is now case-sensitive.

>>> open('thing', 'R')
Traceback (most recent call last):
File "", line 1, in
ValueError: mode string must begin with one of 'r', 'w', 'a' or 'U', not 'R'

* The file itself has a `next` method; `__iter__` simply returns self.

>>> open('day_temps.txt', 'r').next()
'10.3,10.1,9.9,9.9,9.8,9.6,9.0,10.1,10.2,11.1\n'

* Files can be closed automatically using the `with` statement.

>>> with open('things.txt', 'w') as out:
... out.write('I like ducks')