[Tutor] Append mode dilemma

Luke Paireepinart rabidpoobear at gmail.com
Wed Dec 9 19:36:40 CET 2009

On Wed, Dec 9, 2009 at 12:11 PM, biboy mendz <bibsmendez at gmail.com> wrote:

> Hello all!
> I'm trying to use the append mode when opening and writing to a file
> but i cant get it to work my way. When run in the present code,
> the user inputs are expectedly 'appended' but not in a newline below the
> last
> line of the existing file.
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

> fobj = open(fname, 'a')
> fobj.write('\n'.join(all))
> fobj.close()
> Are you aware of how 'join' works?
print "#".join(['a','b','c'])
at the interactive prompt and see if you can't figure out why you're missing
a newline at the end of your output.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091209/fd3b0e06/attachment.htm>

More information about the Tutor mailing list