[Tutor] Append mode dilemma
biboy mendz
bibsmendez at gmail.com
Wed Dec 9 19:49:14 CET 2009
Luke Paireepinart wrote:
> On Wed, Dec 9, 2009 at 12:11 PM, biboy mendz <bibsmendez at gmail.com
> <mailto: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
> outputs.
>
> fobj = open(fname, 'a')
> fobj.write('\n'.join(all))
> fobj.close()
>
> Are you aware of how 'join' works?
> try
> 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.
>
>
> HTH,
> -Luke
>
Hi Luke,
Thank you. To be honest I'm confused of the different string methods
like join(), split(), etc. Anyway I will practice them to see how they work.
--
Regards,
bibs M.
Host/Kernel/OS "cc000002695" running Linux 2.6.31-5.slh.4-sidux-686
[sidux 2009-02 Αιθήρ - kde-full - (200907141427) ]
www.sidux.com
More information about the Tutor
mailing list