The modes for updating files are + suffixed.
r+ Open for reading and writing. The stream is positioned at the
beginning of the file.
w+ Open for reading and writing. The file is created if it does
not exist, otherwise it is trun‐
cated. The stream is p
vanam wrote:
Thanks for your mail.
As you have suggested i have changed the mode to 'rw' but it is
throwing up an error as below
***
IOError: [Errno 22] invalid mode ('rw') or filename: 'data.txt'
***
I am using python 2.6.4.
But Script is managed to pass wit
and there is the everlasting : http://xkcd.com/353/ :D
On Fri, Jan 22, 2010 at 2:16 PM, Stefan Behnel wrote:
> Stefan Lesicnik, 22.01.2010 09:11:
> > I have used the fileinput module for this quiet alot. It has an inplace
> > option which does what you want and a backup option that keeps a back
Stefan Lesicnik, 22.01.2010 09:11:
> I have used the fileinput module for this quiet alot. It has an inplace
> option which does what you want and a backup option that keeps a backup.
>
> http://docs.python.org/library/fileinput.html
> http://www.doughellmann.com/PyMOTW/fileinput/index.html
Ah, r
@vanam:
If you open the file again with only '+w' and not '+rw', I guess you'll not
be getting this error - > IOError: [Errno 22] invalid mode ('rw') or
filename: 'data.txt'
On Fri, Jan 22, 2010 at 1:51 PM, vanam wrote:
> Thanks for your mail.
>
> As you have suggested i have changed the mode
Thanks for your mail.
As you have suggested i have changed the mode to 'rw' but it is
throwing up an error as below
***
IOError: [Errno 22] invalid mode ('rw') or filename: 'data.txt'
***
I am using python 2.6.4.
But Script is managed to pass with 'a+' mode/r+ mo
>
> vanam, 22.01.2010 07:44:
>
> > [Query]: How to write Python string to PYTHON to that file without
> > intact of the full contents
>
> What one would normally do is: read the file (line by line if that's
> ok in
> your case), replace the word by the new one, write the new line to a
> new
> te
Editing original file can be risky at times. If @vanam wants to edit the
same fie, he can open the original file, read it, rename it to say
'data.txt.bak' and then write the modified content to the file named as
'data.txt'. This way he gets the data in the file he wants and also have a
backup of or
vanam, 22.01.2010 07:44:
> [Query]: How to write Python string to PYTHON to that file without
> intact of the full contents
What one would normally do is: read the file (line by line if that's ok in
your case), replace the word by the new one, write the new line to a new
temporary file. When done,
You can try it by reading all data as string, replacing the string and then
write it to target file via opeing it in +w mode.
f = open('data.txt', 'rw').read().replace('Python', 'PYTHON')
f1 = open('data.txt',
'w')
f1.write(f)
HTH
On Fri, Jan 22, 2010 at 12:14 PM, vanam wrote:
> Hi all,
>
> I
10 matches
Mail list logo