Re: File modes

2007-05-11 Thread HMS Surprise
On May 10, 7:11 pm, Jon Pentland <[EMAIL PROTECTED]> wrote: > I don't really see the use for being able to do that. Have you tried > Well, I think I found a reason and it probably happens quite a bit. I open the file and read it into a list. I pop some elements from the list for processing and th

Re: File modes

2007-05-10 Thread Gabriel Genellina
En Thu, 10 May 2007 21:11:16 -0300, Jon Pentland <[EMAIL PROTECTED]> escribió: > I don't really see the use for being able to do that. Have you tried > doing it with the 'app' mode?, But I am guessing that it is just an > advanced mode spawned from 'w'. So, no, I don't think you can do this. In

Re: File modes

2007-05-10 Thread Jon Pentland
I don't really see the use for being able to do that. Have you tried doing it with the 'app' mode?, But I am guessing that it is just an advanced mode spawned from 'w'. So, no, I don't think you can do this. -- http://mail.python.org/mailman/listinfo/python-list

Re: File modes

2007-05-10 Thread Daniel Nogradi
> After reading a file is it possible to write to it without first > closing it? I tried opening with 'rw' access and re-winding. This does > not seem to work unless comments are removed. > > > Also, does close force a flush? > > Thanks, > > jh > > #~~ > > f = open('c:\\

File modes

2007-05-10 Thread HMS Surprise
After reading a file is it possible to write to it without first closing it? I tried opening with 'rw' access and re-winding. This does not seem to work unless comments are removed. Also, does close force a flush? Thanks, jh #~~ f = open('c:\\tempMaxq\\incidents.tx

Re: clarification on open file modes

2007-01-06 Thread Stefan Schwarzer
On 2007-01-05 03:46, tubby wrote: > Is this the safest, most portable way to open files on any platform: > > fp = open(file_name, 'rb') > fp.close() > > I understand that doing the following on Windows to a binary file (a > jpeg or exe files for example) can cause file corruption, is that correct?

Re: clarification on open file modes

2007-01-04 Thread Gabriel Genellina
At Thursday 4/1/2007 23:46, tubby wrote: I understand that doing the following on Windows to a binary file (a jpeg or exe files for example) can cause file corruption, is that correct? fp = open(file_name, 'r') fp.close() How can a simple open in read mode corrupt data??? You can't corrupt *

clarification on open file modes

2007-01-04 Thread tubby
Does a py script written to open and read binary files on Windows affect files on a Linux or Mac machine in a negative way? My concern is portability and safety. I want scripts written within Windows to work equally well on Linux and Mac computers. Is this the safest, most portable way to open

Re: Having trouble with file modes

2006-11-03 Thread Fredrik Lundh
erikcw wrote: > To make it write over the data, I ended up adding, which seems to work > fine. > > f = open('_i_defines.php', 'w+') that doesn't work; you need to use "r+" if you want to keep the original contents. "w+" means truncate first, update then: >>> f = open("foo.txt", "r") >>> f.r

Re: Having trouble with file modes

2006-11-03 Thread Hendrik van Rooyen
"erikcw" <[EMAIL PROTECTED]> wrote: 8< > #loop through patterns list and find/replace data > for o, r in patterns: > data = data.replace(o, r) > print "Replaced %s with %s" % (o, r) > f.write(data) > f.close() > > This results in an empty file. All of the

Re: Having trouble with file modes

2006-11-03 Thread Larry Bates
Don't do that. Do something like renaming the old file to .bak (or .aside or something) and then create the entire file by opening it with 'w'. -Larry -- http://mail.python.org/mailman/listinfo/python-list

Re: Having trouble with file modes

2006-11-03 Thread erikcw
On Nov 3, 4:00 pm, "martdi" <[EMAIL PROTECTED]> wrote: > > At first I was convinced that "w+" was the tool for the job. But now > > I'm finding that the contents of the file are deleted (so I can't read > > the data in).Possible File Modes: &

Re: Having trouble with file modes

2006-11-03 Thread martdi
> At first I was convinced that "w+" was the tool for the job. But now > I'm finding that the contents of the file are deleted (so I can't read > the data in). Possible File Modes: a : Append -- Add data at the end of the file r : Read -- Read from the file w : w

Having trouble with file modes

2006-11-03 Thread erikcw
Hi all, I've created a script that reads in a file, replaces some data (regex), then writes the new data back to the file. At first I was convinced that "w+" was the tool for the job. But now I'm finding that the contents of the file are deleted (so I can't read the data in). f = open('_i_defin