On Wed, Dec 9, 2009 at 1:02 PM, biboy mendz <bibsmen...@gmail.com> wrote:
> > Luke Paireepinart wrote: >> That's because there is NOT a new line at the end of the file. >> It's a file you're appending to, it's up to YOU to create that new line. >> And all files should end with newlines anyway (on linux). >> So modify your code so that you output a new line at the end of your >> outputs. >> >> fobj = open(fname, 'a') >> fobj.write('\n'.join(all)) >> fobj.close() >> >> > Quickie hack just to achieve the newline. Doesn't python have a function > that adds newline automatically in append mode? Why would it need a function for this? Some people might not want a newline, so it can't be automatically enabled. > > > > fobj = open(fname, 'a') > fobj.write('\n'.join(all)) > print > fobj.close() 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') which is shorter than a function call that would enable this feature anyway. This isn't a hack, this is how you're supposed to do this. -Luke
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor