Re: Python path and append

2016-04-29 Thread Steven D'Aprano
On Sat, 30 Apr 2016 06:26 am, boB Stepp wrote: > On Mon, Apr 25, 2016 at 8:51 PM, Steven D'Aprano > wrote: > >> See here for the *start* of a more professional approach: >> >> http://code.activestate.com/recipes/579097-safely-and-atomically-write-to-a-file/ > > What else

Re: Python path and append

2016-04-29 Thread boB Stepp
On Mon, Apr 25, 2016 at 8:51 PM, Steven D'Aprano wrote: > See here for the *start* of a more professional approach: > > http://code.activestate.com/recipes/579097-safely-and-atomically-write-to-a-file/ What else would I need to know/consider in order to have a *complete*

Re: Python path and append

2016-04-27 Thread Stephen Hansen
On Tue, Apr 26, 2016, at 07:56 PM, Seymore4Head wrote: > On Tue, 26 Apr 2016 11:53:57 +1000, Steven D'Aprano > wrote: > > >On Tue, 26 Apr 2016 08:04 am, Seymore4Head wrote: > > > >> BTW I was trying to use a line like yours that used an output file > >> that didn't exist and

Re: Python path and append

2016-04-26 Thread Chris Angelico
On Wed, Apr 27, 2016 at 12:56 PM, Seymore4Head wrote: > On Tue, 26 Apr 2016 11:53:57 +1000, Steven D'Aprano > wrote: > >>On Tue, 26 Apr 2016 08:04 am, Seymore4Head wrote: >> >>> BTW I was trying to use a line like yours that used an output file

Re: Python path and append

2016-04-26 Thread Seymore4Head
On Tue, 26 Apr 2016 19:16:56 +0100, Michael wrote: >If you want to read an entire file, append a space and asterisk and write it >to another file, this is the code you need: > >infile = open('win.txt', 'r') >text = f.read() >infile.close() >text += " *" >outfile =

Re: Python path and append

2016-04-26 Thread Seymore4Head
On Tue, 26 Apr 2016 11:53:57 +1000, Steven D'Aprano wrote: >On Tue, 26 Apr 2016 08:04 am, Seymore4Head wrote: > >> BTW I was trying to use a line like yours that used an output file >> that didn't exist and was getting an error.  I assume that import os >> fixes that. > >

Re: Python path and append

2016-04-26 Thread Michael
If you want to read an entire file, append a space and asterisk and write it to another file, this is the code you need: infile = open('win.txt', 'r') text = f.read() infile.close() text += " *" outfile = open('outfile.txt', 'w') outfile.write(text) outfile.close() If, on the other hand, you

Re: Python path and append

2016-04-26 Thread Gregory Ewing
Steven D'Aprano wrote: (Possible a few very old operating systems on supercomputers from the 1970s or 80s may have supported inserting... I seem to recall that VMS may have allowed that... but don't quote me.) I wouldn't be surprised if VMS provided some sort of indexed random-access file

Re: Python path and append

2016-04-25 Thread Dan Sommers
On Tue, 26 Apr 2016 11:51:23 +1000, Steven D'Aprano wrote: > ... (Possible a few very old operating systems on supercomputers from > the 1970s or 80s may have supported inserting... I seem to recall that > VMS may have allowed that... but don't quote me.) Some [non-supercomputer]

Re: Python path and append

2016-04-25 Thread Steven D'Aprano
On Tue, 26 Apr 2016 08:04 am, Seymore4Head wrote: > BTW I was trying to use a line like yours that used an output file > that didn't exist and was getting an error.  I assume that import os > fixes that. Why would you assume that? "Doctor, I have a problem with my arm, but I won't tell you

Re: Python path and append

2016-04-25 Thread Steven D'Aprano
On Tue, 26 Apr 2016 05:00 am, Seymore4Head wrote: > I was reading that. I have read it before. I don't use python enough > to even remember the simple stuff. Then when I try to use if for > something simple I forget how. It is perfectly fine to forget things that you read weeks or months

Re: Python path and append

2016-04-25 Thread Chris Angelico
On Tue, Apr 26, 2016 at 7:26 AM, John Gordon wrote: > It's much easier to create a new file and then rename it afterwards, > instead of rewriting the original file. And more importantly, it's safer. If anything happens to your process while it's doing its work, you'll have a

Re: Python path and append

2016-04-25 Thread Seymore4Head
On Mon, 25 Apr 2016 21:26:34 + (UTC), John Gordon wrote: >In <27nshbp40p1llr231dqm31p754tvurk...@4ax.com> Seymore4Head > writes: > >> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head >> wrote: > >> I am going to

Re: Python path and append

2016-04-25 Thread Peter Otten
Random832 wrote: > On Mon, Apr 25, 2016, at 16:15, Seymore4Head wrote: >> Thanks for the tip. >> >> Still broke. :( >> >> f = open('wout.txt', 'r+') >> for line in f: >> if line=="": >> exit >> line=line[:-1] >> line=line+" *" >> f.write(line) >> print line >>

Re: Python path and append

2016-04-25 Thread John Gordon
In <27nshbp40p1llr231dqm31p754tvurk...@4ax.com> Seymore4Head writes: > On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head > wrote: > I am going to forget using a directory path. > I would like to take the file win.txt and append a

Re: Python path and append

2016-04-25 Thread Seymore4Head
ing some other character. It's safer to use >line.rstrip("\n"). > >> -Original Message- >> From: Python-list >> [mailto:python-list-bounces+joaquin.alzola=lebara@python.org] On Behalf >> Of Seymore4Head >> Sent: 25 April 2016 20:01 >>

Re: Python path and append

2016-04-25 Thread Random832
On Mon, Apr 25, 2016, at 16:15, Seymore4Head wrote: > Thanks for the tip. > > Still broke. :( > > f = open('wout.txt', 'r+') > for line in f: > if line=="": > exit > line=line[:-1] > line=line+" *" > f.write(line) > print line > f.close() Your problem is that after

Re: Python path and append

2016-04-25 Thread Seymore4Head
t;Sent: 25 April 2016 20:01 >To: python-list@python.org >Subject: Re: Python path and append > >On Mon, 25 Apr 2016 18:24:02 - (UTC), Rob Gaddi ><rgaddi@highlandtechnology.invalid> wrote: > >>Seymore4Head wrote: >> >>> On Tue, 19 Apr 2016 18:29:38 -0400,

Re: Python path and append

2016-04-25 Thread MRAB
ne[:-1] could be removing some other character. It's safer to use line.rstrip("\n"). -Original Message- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara@python.org] On Behalf Of Seymore4Head Sent: 25 April 2016 20:01 To: python-list@python.org Subject: Re: Python

Re: Python path and append

2016-04-25 Thread Rob Gaddi
Seymore4Head wrote: > On Mon, 25 Apr 2016 18:24:02 - (UTC), Rob Gaddi > wrote: > >>Seymore4Head wrote: >> >>> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head >>> wrote: >>> >>> I am going to forget using a directory path. >>>

RE: Python path and append

2016-04-25 Thread Joaquin Alzola
ist [mailto:python-list-bounces+joaquin.alzola=lebara@python.org] On Behalf Of Seymore4Head Sent: 25 April 2016 20:01 To: python-list@python.org Subject: Re: Python path and append On Mon, 25 Apr 2016 18:24:02 - (UTC), Rob Gaddi <rgaddi@highlandtechnology.invalid> wrote: >Seymor

Re: Python path and append

2016-04-25 Thread Seymore4Head
On Mon, 25 Apr 2016 18:24:02 - (UTC), Rob Gaddi wrote: >Seymore4Head wrote: > >> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head >> wrote: >> >> I am going to forget using a directory path. >> I would like to take the file

Re: Python path and append

2016-04-25 Thread Rob Gaddi
Seymore4Head wrote: > On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head > wrote: > > I am going to forget using a directory path. > I would like to take the file win.txt and append a space and the * > symbol. > > f = open('win.txt', 'r+') > for line in f: >

Re: Python path and append

2016-04-25 Thread Seymore4Head
On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head wrote: I am going to forget using a directory path. I would like to take the file win.txt and append a space and the * symbol. f = open('win.txt', 'r+') for line in f: f.read(line) f.write(line+" *") This

Re: Python path and append

2016-04-19 Thread Matthew Barnett
On 2016-04-19 23:38, Chris Angelico wrote: On Wed, Apr 20, 2016 at 8:29 AM, Seymore4Head wrote: handle = open("\\Winmx\New$\q.txt") for line in handle: line=line.strip() print line Traceback (most recent call last): File "\\Winmx\New$\add viewed.py",

Re: Python path and append

2016-04-19 Thread Chris Angelico
On Wed, Apr 20, 2016 at 8:29 AM, Seymore4Head wrote: > > handle = open("\\Winmx\New$\q.txt") > for line in handle: > line=line.strip() > print line > > > Traceback (most recent call last): > File "\\Winmx\New$\add viewed.py", line 2, in > handle =

Python path and append

2016-04-19 Thread Seymore4Head
This doesn't work. Does Python recognize hidden directories? handle = open("\\Winmx\New$\q.txt") for line in handle: line=line.strip() print line Traceback (most recent call last): File "\\Winmx\New$\add viewed.py", line 2, in handle = open("\\Winmx\New$\q.txt") IOError: