How does f=open('mytext.txt', 'w+') work?
Alex
lidenalex at yahoo.se
Sun Sep 18 12:11:51 EDT 2005
Rossum's tutorial on Python states:
"open() returns a file object, and is most commonly used with two
arguments: 'open(filename, mode)'
mode 'r+' opens the file for both reading and writing."
Here's a little session in Python's interactive window
>>> f=open('mytext.txt','w+')
>>> f.write('My name is Bob')
>>> s=f.read()
>>> s.len()
>>> len(s)
4082
>>>f.close()
If I open the file mytext.txt in Notepad I see something that begins
with
"My name is Bob VwMÚ¸x¶ Ð
"
and goes on for approximately 4082 characters.
What's happening??
Alex
More information about the Python-list
mailing list