Re: [Tutor] Append mode dilemma

2009-12-09 Thread Alan Gauld
"Lie Ryan" wrote with open(...) as fobj: entry = '' while entry != '.' fobj.write(raw_input()) But how does entry change in this example? I think you need with open(...) as fobj: entry = '' while entry != '.' fobj.write(entry) entry = raw_input()

Re: [Tutor] Append mode dilemma

2009-12-09 Thread Luke Paireepinart
On Wed, Dec 9, 2009 at 2:46 PM, Lie Ryan wrote: > On 12/10/2009 6:12 AM, Luke Paireepinart wrote: > >> 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') >> > > except that if you're joining a very long string, y

Re: [Tutor] Append mode dilemma

2009-12-09 Thread Lie Ryan
On 12/10/2009 6:12 AM, Luke Paireepinart wrote: 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') except that if you're joining a very long string, you'll have python copy the whole string again. better to just

Re: [Tutor] Append mode dilemma

2009-12-09 Thread biboy mendz
-- Regards, bibs M. Host/Kernel/OS "cc02695" running Linux 2.6.31-5.slh.4-sidux-686 [sidux 2009-02 Αιθήρ - kde-full - (200907141427) ] www.sidux.com Albert Sweigart wrote: Your problem is on this line: fobj.write('\n'.join(all)) This puts a newline in between each line in "all", but

Re: [Tutor] Append mode dilemma

2009-12-09 Thread Albert Sweigart
Your problem is on this line: fobj.write('\n'.join(all)) This puts a newline in between each line in "all", but not at the end. The fix is simple: fobj.write('\n'.join(all) + '\n') This will make sure that the last line has a newline at the end of it, so that when you later append data, it will

Re: [Tutor] Append mode dilemma

2009-12-09 Thread Luke Paireepinart
On Wed, Dec 9, 2009 at 1:02 PM, biboy mendz 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

Re: [Tutor] Append mode dilemma

2009-12-09 Thread biboy mendz
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 output

Re: [Tutor] Append mode dilemma

2009-12-09 Thread Luke Paireepinart
On Wed, Dec 9, 2009 at 12:49 PM, biboy mendz wrote: > >> Are you aware of how 'join' works? >> > 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. > > > It's very important to practice t

Re: [Tutor] Append mode dilemma

2009-12-09 Thread biboy mendz
Luke Paireepinart wrote: On Wed, Dec 9, 2009 at 12:11 PM, biboy mendz > 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 expect

Re: [Tutor] Append mode dilemma

2009-12-09 Thread Luke Paireepinart
On Wed, Dec 9, 2009 at 12:11 PM, biboy mendz 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

[Tutor] Append mode dilemma

2009-12-09 Thread biboy mendz
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. Instead it starts from where the last line end.