What happens after return statement?
gustafl at algonet.se
Mon Oct 21 05:41:17 CEST 2002
I really ought to know better after 2 years with Python, but I became
uncertain. Have a look, please:
# Return the contents of a file (strip DOCTYPE conditionally)
def read_file(file, remove):
f = open(file, 'r')
if remove = 0: # Just read the file
else: # Read the file and remove any line starting with '<!DOCTYPE'
sum = ""
line = f.readline()
if line = "": break
if line[:9] != '<!DOCTYPE':
sum = sum + line
f.close() # Is the file closed (in both cases) here?
Is the file closed, or is it not? That is, what happens after each return
More information about the Python-list