[Tutor] Append mode dilemma
Lie Ryan
lie.1296 at gmail.com
Wed Dec 9 21:46:44 CET 2009
On 12/10/2009 6:12 AM, Luke Paireepinart wrote:
> This won't work unless you have STDOUT redirected to your file. It
> would be better just to do
> fobj.write('\n'.join(all) + '\n')
except that if you're joining a very long string, you'll have python
copy the whole string again.
better to just redirect print
print >> fobj, '\n'.join(all)
but since this is a file object we're talking about, you can write while
getting user input.
with open(...) as fobj:
entry = ''
while entry != '.'
fobj.write(raw_input())
More information about the Tutor
mailing list