[Tutor] appending to a file on a new line
ADRIAN KELLY
kellyadrian at hotmail.com
Thu Jan 19 16:04:40 CET 2012
guys,
its a text file i am writing to and when i write the first time its fine, i get 3 lines of input collected from a user and written to my text file, however if i run the program again the next 3 lines begin at the end of the previous users details. It works fine but starts from where the pointer left off. i dont know how to solve this. where do i put the '\n'? to be honest the .join i dont understand but otherwise it prints as a list e.g. ('name','age','etc')
Adrian
> Date: Thu, 19 Jan 2012 09:42:45 -0500
> Subject: Re: [Tutor] appending to a file on a new line
> From: joel.goldstick at gmail.com
> To: kellyadrian at hotmail.com
> CC: tutor at python.org
>
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120119/d3dc75c1/attachment.html>
More information about the Tutor
mailing list