[Tutor] appending to a file on a new line

Joel Goldstick joel.goldstick at gmail.com
Thu Jan 19 15:42:45 CET 2012


On Thu, Jan 19, 2012 at 9:32 AM, ADRIAN KELLY <kellyadrian at hotmail.com> wrote:
> Hi everyone,
> is there an easy way to write to a file (that already exists with data
> contained) on a new line.  I understand that the file pointer appends where
> it left off but how do i write to the next line or even skip a line if
> possible?
>
> User_info=open("C:\\Documents and
> Settings\\akelly\\Desktop\\details.txt",'a')
> User_info.write("\n".join(Details))
>
>
> all the best,
> Adrian
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
What you wrote looks fine.  When you open a file to append, it does
just that with the write method.

You can learn more here
http://docs.python.org/tutorial/inputoutput.html#methods-of-file-objects

When you run your code what happens?


-- 
Joel Goldstick


More information about the Tutor mailing list