[Tutor] File mode r+

Shitiz Bansal shitizb at yahoo.com
Fri Sep 30 23:43:58 CEST 2005


Hi,
Thats strange. Maybe me being on windows makes the
diference.
Here is the exact IDLE session to clarify:

    
IDLE 1.1      ==== No Subprocess ====
>>> 
>>> file1=open("aa.txt",'r+')
>>> file1.read()
'abcd\nefgh\nijkl\nmnop\nqrst\nuvwx\nyx12\n'
>>> file1.close()
>>> file1=open("aa.txt",'r+')
>>> file1.readline()
'abcd\n'
>>> file1.seek(0,1)
>>> file1.write("1234\b")
>>> file1.close()
>>> file1=open("aa.txt",'r+')
>>> file1.read()
'abcd\n1234\x08\nijkl\nmnop\nqrst\nuvwx\nyx12\n'
>>> 

I find this very very strange.

shitiz.

--- "Michael P. Reilly" <arcege at gmail.com> wrote:

> On 9/27/05, Shitiz Bansal <shitizb at yahoo.com> wrote:
> >
> > Hi,
> > thanx..it works fine. As for the structure of the
> > file...i decided to pad every line with extra
> spaces
> > to make the length of each line constant.That way
> i
> > can replace any line with another without being
> > bothered about the number of characters.
> > However my curiosity got better of me again...:D.
> > i tried to insert a /b character(i had a notion it
> > represents backspace) to see if it would work.
> > It inserted a bit of unicode in the file(Mind you,
> > inserted . Not replaced)
> > original file:
> >
> > 'abcd\nefgh\nijkl\nmnop\nqrst'
> >
> > code::
> > file1=open("aa.txt",'r+')
> > file1.readline()
> > file1.seek(0,1)
> > file1.write("1234\b")
> > file1.close()
> >
> > newfile:
> >
> > 'abcd\n1234\x08\nijkl\nmnop\nqrst'
> >
> > How does that come to pass?
> >
> >
> I didn't get what you got exactly. I got:
> 
> 'abcd\0121234\010ijkl\012mnop\012qrst'
> 
> \012 => \n and
> \010 => \b (\x08)
> 
> I'm not sure why you would have gotten '\x08\n' in
> the same sequence. Maybe
> you should look again. Incidently, when I try to
> print aa.txt, I get:
> abcd
> 123ijkl
> mnop
> qrst
> which is what I would expect.
> -Arcege
> --
> There's so many different worlds,
> So many different suns.
> And we have just one world,
> But we live in different ones.
> 



		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com


More information about the Tutor mailing list