Help Please

N

newb.py

In the book I am using, they give the following function as an
example:

def copyFile(oldFile, newFile):
f1 = open(oldFile, 'r')
f2 = open(newFile, 'w')
while True:
text = f1.read(50)
if text == "":
break
f2.write(text)
f1.close()
f2.close()
return

My question is why does this function successfully copy a 200
character file, oldFile, to newFile? The line of code that reads,
text
= f1.read(50), does not seem to be iterative in any way to me. How is
this fuction succeding in adding each additional set up 50 characters
to the previous set of 50 characters read from oldFile?
How does it even succeed in copying a 25 character file? If oldFile
contains 25 characters, how does the program ever break out of the
'while True:' loop?

I just don't see it.

Again, much thanks to anyone who can clear this up.

-Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top